Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read data from nested JSON #104

Open
anhvuong1 opened this issue Oct 25, 2018 · 0 comments
Open

How to read data from nested JSON #104

anhvuong1 opened this issue Oct 25, 2018 · 0 comments

Comments

@anhvuong1
Copy link

anhvuong1 commented Oct 25, 2018

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant