0

Good afternoon,

I am passing a JSON string to an iOS app and an Android app from a webservice. Business rules dictate that this JSON string CAN contain data with a quotation mark.

{"message": [{"MessageID": "22", "CompanyID": "0897001", "MessageText": "this "message" has quotes", "JobID": "BT201-Main-1-031508-134700", "AttachmentCount": "0", "MainDevice": "1"},{"MessageID": "23", "CompanyID": "0897001", "MessageText": "this message has  no quotes", "JobID": "BT201-Main-1-031508-134700", "AttachmentCount": "0", "MainDevice": "1"}]}

After doing a little google-ing, I have found that if I want to send data with quotation marks enclosed, I just need to preface the quotation marks inside of the value with a backslash:

{"MessageID": "22", "CompanyID": "0897001", "MessageText": "this \"message\" has quotes", "JobID": "BT201-Main-1-031508-134700", "AttachmentCount": "0", "MainDevice": "1"}

When the android app gets this JSON, it parses it beautifully. The data displays in the view with quotes and all. Not so with the iOS app. What can I do to the JSON to get the iOS app to properly parse the JSON? I am currently using SBJSON in my iOS app. Any help would be greatly appreciated. Thanks!

AaronBastian
  • 307
  • 3
  • 13
  • Perhaps you could describe what does happen (especially if you're getting an error back), and show the code you're using to deserialize this input? – Sixten Otto Aug 22 '12 at 21:49
  • I'm sorry about that. As I walk through the parsing process, the parser skips the backslash as an escape character, and stops the parsing of the value at the next quotation mark: "this \". It finds no comma after what it considers an end quote, and throws an "Object Key String Expected" error (part of the SBJsonParser). I hope that this helps! – AaronBastian Aug 23 '12 at 13:13
  • Which version of SBJson are you using? – Stig Brautaset Aug 24 '12 at 14:59

2 Answers2

0

What is the problem with iOS. Are you getting the backslash as well? In this case, what about a pattern replacement?

Jose L Ugia
  • 5,960
  • 3
  • 23
  • 26
0

Can you see that the JSON you are feeding the parser actually has the \" in it? How is the JSON generated? SBJson does handle embedded quotes correctly. Here's a link to the particular part of the test suite that explicitly checks for it:

https://github.com/stig/json-framework/tree/master/Tests/Data/valid/string/escapes

Stig Brautaset
  • 2,602
  • 1
  • 22
  • 39