Steve Webster
Steve Webster

Reputation: 111

Android Parse a JSON String With Quotes in Keys and Values

Android JSON parsing is rather straightforward until it comes to have json reserved characters in your keys/values. I have JSON coming from an HTTP socket whose response is put into a string variable. It looks like this

{"ZboAdtPw4bA":"Ben Heck"s PlayStation 4 Slim Teardown","iC4qIx72_Cc":"Ben Heck's Xbox Slim Teardown"}

See the double quotation in the first value? It even screws up on StackOverflows web page. How am I supposed to escape/prevent this from happening? If I do a:

response = response.replace("\"", "");

Then all the double quotation get replaced, not just the ones in the key/value pair. This is because its all contained in one string at the moment. I am wondering if there is an easy way to do this with android. And of course, java answers are acceptable to. Now I could do this since its just a single dimensional key/value pair easily, I may not even need JSON, but I would like to adhere to standards.

Upvotes: 0

Views: 573

Answers (1)

Sarah Maher
Sarah Maher

Reputation: 830

you are simply trying to ruin the basic of a JSON . you simply add "/"" to the java code .

other than that its not possible for the parser to differentiate between the quotations from the JSON format or the quotations in the string .

Upvotes: 1

Related Questions