0

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.

Thib L
  • 704
  • 1
  • 8
  • 20
  • Please show your code, and note where the crash occurs. My guess is that it will be where you read the result, not in the parser itself. – Stig Brautaset Oct 09 '12 at 16:25

1 Answers1

1

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

Mikhail Viceman
  • 604
  • 3
  • 9