Tuesday, February 26, 2013

Sinister Trap-Json Object vs Json Array

Badu made a change server side that allowed me to proceed with the default sync of contacts by uploading a  json array to the server. 4 hrs later and I was racking my brain why his server kept returning a 500(Internal Server Error) response until I found out that I was submitting a json object instead of array.

What's the difference?
Json object is demarcated by {} while json array is demarcated by [ ]. Yeah, it really was that trivial.

Here's the bit of code that I used to change my object to array

JSONArray json_array = new JSONArray();
json_array.put(json);
String params = "action=sync&phone="+phone+"&contacts="+json_array.toString();

No comments:

Post a Comment