Skip to content

How to read data from nested JSON #104

@anhvuong1

Description

@anhvuong1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions