Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

Reading Multiple JSON objects in java

{"phone":1234,"name":"rose","key":1,"country":"india"} 
{"phone":6789,"name":"jasmine","key":2,"country":"india"}

while reading this type of json data ,I'm getting this error:

Unexpected token LEFT BRACE({) at position 54.
    at org.json.simple.parser.JSONParser.parse(JSONParser.java:146)
    at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)

Could anyone please help me resolve this error?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You seem to have 2 lines of JSON. Each line is a valid JSON object/document in of itself, however if you pass both lines together then it would not be a valid JSON document. Your options are

  1. Read each line as a separate entry and invoke the JSON parser on that line to produce a JSON object.

  2. Use an array to process both lines:

    [ {"phone":1234,"name":"rose","key":1,"country":"india"}, {"phone":6789,"name":"jasmine","key":2,"country":"india"} ]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...