0

i'm trying to parse json array response from server. for example i can simply parse this response :

echo json_encode(['result' => 0,'h'=>1,'m'=>2]);

but for parse this json format:

echo json_encode(['result' => 0,'hour'=>1,'minute'=>2]);

i get this error:

 E/Response:: {"result":0,"hour":"1","minute":"35"}
 E/AndroidRuntime: FATAL EXCEPTION: main
 E/AndroidRuntime: Process: pishguy.ir.asrebidree, PID: 6322
 E/AndroidRuntime: java.util.UnknownFormatConversionException: Conversion: س
 E/AndroidRuntime:     at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1399)

My code:

JSONObject jsonObject = new JSONObject(response);
String result = jsonObject.getString("result");

if (result.equals("0")) {
    String hore = jsonObject.getString("hour");
    String minute = jsonObject.getString("minute");
}

UPDATED

problem is hour and minute words, not result key in json array. after change hour and minute to h and m problem solved

1
  • value of "result" key is int not the string Commented Oct 9, 2015 at 9:16

1 Answer 1

2

Your result is contian int value...try this

int result = jsonObject.getInt("result");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.