1

I am writing an application to get the json object from server.
for example:

{"23423423", [abc, 2009-10-12, hello]}  

My problem is: if abc is a string that contains comma, then how can I parse the content in square brackets? normally it should be three items in the square brackets. But if abc contains a comma, then I will get four items, which is not right.
Any ideas ?

Thanks in advance !

EDIT:

JSONObject obj = new JSONObject(); 
List list = new ArrayList(); 
list.add("abc"); 
list.add("2009-10"); 
obj.put("234234", list.toString());// don't use toString();

Finally I solve it, I should not use the list.toString(), otherwise the whole list will be converted to a string.

2 Answers 2

7

If abc is a string, then it should be coming from the server quoted, as "abc". If it isn't, then whatever created the JSON is doing it wrong.

Sign up to request clarification or add additional context in comments.

3 Comments

+1. Exactly. And if it's quoted, a decent JSON parser should handle it just fine.
it's a string but after I put it into a list, the quoted lost
I use following code: JSONObject obj = new JSONObject(); List list = new ArrayList(); list.add("abc"); list.add("2009-10"); obj.put("234234", list.toString()); and finally I got the result above.
1

A decent JSON parser handles that. Why not just use one of the existing C# JSON parsers out there, such as JSONSharp?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.