Reputation: 714
I am working on a webservice in Json with SBJson.
When I receive something like that there is no problem :
{"error":"The operation failed"}
But When I receive something like that, it crashes the app :
[{"id":"29"}]
Does anybody have an idea ?
Thank you very much for your time.
Upvotes: 0
Views: 125
Reputation: 604
The difference between {"error":"The operation failed"}
and [{"id":"29"}]
:
the first one is Object (an unordered collection of key:value pairs with the ':' character separating the key and the value, comma-separated and enclosed in curly braces; the keys must be strings and should be distinct from each other);
the second one is Array (an ordered sequence of values, comma-separated and enclosed in square brackets; the values do not need to be of the same type).
In your app, you handle JSON response in Dictionary - which suits for {"error":"The operation failed"}
case, but is wrong for second case (which is an array) - [{"id":"29"}]
.
(With dictionary you can execute - objectForKey:
, and with array - objectAtIndex:
).
To understand, how it works, you can read more about JSON:
http://en.wikipedia.org/wiki/JSON
Upvotes: 1