简体   繁体   中英

Read multipile JSON objects from single file with Jackson

I'm using Jackson 2.6.5 . I'm trying to read the following JSON:

{
    "metadata1":"value",
    "metadata2":"value"
}
{   
    "field1":"value",
    "field2":"value",
    ....
}

With the following code:

JSONObject jsonObj = new JSONObject(jsonString);

But jsonObj contains only the "first" part of my JSON (the metadata), How can I read the "second" part of my JSON? (the part with the fields)?

EDIT

I know that my JSON doesn't contain "," so how can I parse it without "," between the jsons?

Seems like the JSON you added is missing a , sign between the two objects.

If you get such an non-json as input string, you might want to consider to:

  1. First manipulate the input string by adding it the missing , . Eg find the location of }{ and replace it with },{
  2. And only then to insert it to the jackson
  1. Your json is invalid, so you can't parse invalid json scheme by json parsing tools out of the box,
  2. Instead you could read file by yourself into 2 strings - one valid json per string and then parse it with any json parser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM