Skip to content Skip to sidebar Skip to footer

Json Android: Parsing Json

I have a json : [ {user:'John',s:'Ldh',e:'usa'},{user:'Paul',s:'bukit panjang ',e:'FedExForum - Memphis'},{user:'ross',s:'bukit panjang ',e:'FedExForum - Memphis '}] I am parsing

Solution 1:

optString : Get an optional string associated with a key.

I don't see the key u in your JSON object, shouldn't it be user = obj.optString("user");


Solution 2:

JSON formatting

Your JSON data is not valid, it's valid as javascript, but not as JSON.

All properties should be quoted in JSON:

[
 { "user": "John", "s": "Ldh", "e": "usa"},
 { "user":"Paul", "s":"bukit panjang ", "e": "FedExForum - Memphis" },
 { "user": "ross", "s":"bukit panjang ", "e":"FedExForum - Memphis "}
]

Indentation is not needed, I just did it to make it clearer.

Missing field

Your parser seems to ignore that your input data is invalid. Other problem could be as others mentioned you're requesting the u property at user = obj.optString("u"); which does not exists.


Post a Comment for "Json Android: Parsing Json"