简体   繁体   中英

json deserializing

Just starting so any facilitation appreciated. Have an object serialized it to this starting segment:

[{"boo00":true,"lineItem":[{"bool00":true,"display":false,"extra00":"objectType","status":"","value":"recordType:A"}, {"bool00":true,"display":false,"extra00":"0","status":"","value":"UPC:1"},{...},{...}],"rowId":0,"str00":"hidden"},

The object has four elements: boo00 (boolean), lineIem (ArrayList), rowID (int), str00 (String)

I have this segment where I am trying to understand how to build back my object

String flatten = lines.toString();
JSONObject outer = JSONObject.fromObject(flatten);
Iterator itr04 = null;
for(itr04 = outer.entrySet().iterator(); itr04.hasNext();){
    Map.Entry entry = (Map.Entry) itr04.next();
    String key = (String)entry.getKey();
    System.out.println("key= "+key);
}

I am getting the following exception:

"net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of []"

which at this point makes little sense to me because that is exactly how it starts.

Your JSON text begins with a square bracket: [ , not a curly brace: { . The JSON string represents an array of objects.

Your outer should be a JSONArray .

Since the Java JSON stuff is sort of brain dead, one thing you can do is concatenate "[" and "]" to the front and end of the string. Then you can always use JSONArray to read the string, and then do instanceof on each array element to find out what you have.

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