SBJson Stream Parser crashes
-
06-07-2021 - |
Vra
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.
Oplossing
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: