1

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.

2 Answers 2

3

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)

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

1 Comment

And i feel dumb... Yes this solves everything with no effort. Thanks alot! :)
0

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;

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.