Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I get a String in the following format:

    String buffer = "[{\"field1\": 11,\"field2\": 12,\"field3\": 13}]";

and want to convert it to a JSONArray. Thus i use the following code:

    JSONArray Jarray = CDL.toJSONArray(buffer);

My Problem is now i get the following exception:

    org.json.JSONException: Bad character ':' (58). at 24 [character 25 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:432)
at org.json.CDL.rowToJSONArray(CDL.java:113)
at org.json.CDL.toJSONArray(CDL.java:193)
at org.json.CDL.toJSONArray(CDL.java:182)
at MyDataexchange.MyCVSConverter.convertJson(MyCVSConverter.java:44)
at Mainexe.DataTest.main(DataTest.java:22)

As you can see in the stacktrace i want to use this to convert the string to .cvs at the end ;). Since i dont know how to do it in a better way i'd like to know how to fix this exception. Do i need to substitute the ':' with anything? (Substitue ':' to ',' would produce null for example but not throw an exception, still it doesnt help me :( ) If yes it would be nice to tell me with what, otherwise any suggestions are welcome.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

org.json.CDL is for parsing and serializing comma delimited text. However, your sample string is not comma delimited text. It's JSON. You probably wanted JSONArray Jarray = new JSONArray(buffer)

share|improve this answer
    
And i feel dumb... Yes this solves everything with no effort. Thanks alot! :) –  Dave yesterday
add comment

Ok, here's a better way of doing this (similar to what "guest" said):

String s = "[{\"field1\": 11,\"field2\": 12,\"field3\": 13}]";
Object obj=JSONValue.parse(s);
JSONArray array=(JSONArray)obj;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.