kishan
kishan

Reputation: 54

How to get this json format value?

I want to get value from json.But I can't get value. I want to get 26/08/15 value.

json format:

{"Timestamp":["26/08/15"]}

My code :

JSONArray timestamp = jsonObj .getJSONArray("Timestamp");
JSONObject timecatObj = (JSONObject) timestamp.get(0);
Iterator temp = timecatObj.keys();
serverdate = temp.toString();

Upvotes: 0

Views: 101

Answers (2)

WineYe
WineYe

Reputation: 51

{"Timestamp":["26/08/15"]}, the value of "Timestamp" is a JSONArray, but the element of the JSONArray is String not JSONObject.

So, the code should be :

JSONArray timestamp = jsonObj.getJSONArray("Timestamp");
String serverdate = timestamp.optString(0);

Upvotes: 0

Suhail Mehta
Suhail Mehta

Reputation: 5542

JSONObject ob = new JSONObject("{"Timestamp":["26/08/15"]}")
JSONArray arr = ob.optJSONArray("Timestamp",null);
String date = arr.optString(0);

Upvotes: 1

Related Questions