ralfstx / minimal-json

A fast and small JSON parser and writer for Java
MIT License
732 stars 186 forks source link

How to read data from nested JSON #104

Open anhvuong1 opened 5 years ago

anhvuong1 commented 5 years ago

Hi team,

I worked on JSON Minimal in recent time. Some things look good. But for now. I got the JSON as below: { "status": "OK", "result": { "user": [ { "_id": "123", "type": "worker" }, { "_id": "129", "type": "architect" } ] } }

For now, I want to get data from each of key "_id". For the first. I tried to implement JsonArray as below:


JsonObject JsonObject = JsonObject.readFrom( jsonString );
JsonArray items = jsonObject.get( "result.user" ).asArray();

Then get the exception:
**javax.script.ScriptException: Sourced file: inline evaluation of: ``import com.eclipsesource.json.JsonArray; import com.eclipsesource.json.JsonObjec . . . '' : Typed variable declaration : Attempt to resolve method: get() on undefined variable or class name: jsonObject : at Line: 9 : in file: inline evaluation of: ``import com.eclipsesource.json.JsonArray; import com.eclipsesource.json.JsonObjec . . . '' : jsonObject .get ( "result.account" ) 
 in inline evaluation of: ``import com.eclipsesource.json.JsonArray; import com.eclipsesource.json.JsonObjec . . .** 

I think look like the format Json node "result.user" doesn't follow to standard JSON Minimal. Please let me know if you has any the way to define code for better in behavior to print each of "_id" value from the JSON above

Many thanks