-5

I've got this Json code from a web service and i would like to extract the value "percentage" for the attribute Adventurousness , Artistic interests, "Emotionality, Imagination and "Intellect". This is my json:

"tree": {
"id": "r",
"children": [
{
"id": "personality",
"children": [
{
"id": "Openness_parent",
"children": [
{
"id": "Openness",
"children": [
{
"id": "Adventurousness",
"category": "personality",
"sampling_error": 0.114811472,
"percentage": 0.8226079753697427,
"name": "Adventurousness"
},
{
"id": "Artistic interests",
"category": "personality",
"sampling_error": 0.2144372,
"percentage": 0.13816359141015402,
"name": "Artistic interests"
},
{
"id": "Emotionality",
"category": "personality",
"sampling_error": 0.123022336,
"percentage": 0.20056338400200477,
"name": "Emotionality"
},
{
"id": "Imagination",
"category": "personality",
"sampling_error": 0.154087616,
"percentage": 0.9696658432125749,
"name": "Imagination"
},
{
"id": "Intellect",
"category": "personality",
"sampling_error": 0.136331168,
"percentage": 0.9564220341561931,
"name": "Intellect"
},
{
"id": "Liberalism",
"category": "personality",
"sampling_error": 0.176828144,
"percentage": 0.9648028479821156,
"name": "Authority-challenging"
}
],
"category": "personality",
"sampling_error": 0.139738032,
"percentage": 0.9708325493254609,
"name": "Openness"
},
{
"id": "Conscientiousness",
"children": [
{
"id": "Achievement striving",
"category": "personality",
"sampling_error": 0.146753584,
"percentage": 0.5341763575314873,
"name": "Achievement striving"
},
{
"id": "Cautiousness",
"category": "personality",
"sampling_error": 0.171268448,
"percentage": 0.8691133238234481,
"name": "Cautiousness"
},
{
"id": "Dutifulness",
"category": "personality",
"sampling_error": 0.2170492,
"percentage": 0.09921530294410037,
"name": "Dutifulness"
},
{
"id": "Orderliness",
"category": "personality",
"sampling_error": 0.14138663999999998,
"percentage": 0.17228482742960108,
"name": "Orderliness"
},
{
"id": "Self-discipline",
"category": "personality",
"sampling_error": 0.175971392,
"percentage": 0.1965291658499149,
"name": "Self-discipline"
},
{
"id": "Self-efficacy",
"category": "personality",
"sampling_error": 0.18749456,
"percentage": 0.7617018095044775,
"name": "Self-efficacy"
}
],
"category": "personality",
"sampling_error": 0.160965584,
"percentage": 0.5760790305792012,
"name": "Conscientiousness"
},
{
"id": "Extraversion",
"children": [
{
"id": "Activity level",
"category": "personality",
"sampling_error": 0.22661856,
"percentage": 0.009443641327733596,
"name": "Activity level"
},
{
"id": "Assertiveness",
"category": "personality",
"sampling_error": 0.21824792,
"percentage": 0.15438472546229354,
"name": "Assertiveness"
},
{
"id": "Cheerfulness",
"category": "personality",
"sampling_error": 0.16958656,
"percentage": 0.04323817864508592,
"name": "Cheerfulness"
},
{
"id": "Excitement-seeking",
"category": "personality",
"sampling_error": 0.16988792,
"percentage": 0.025333905110705292,
"name": "Excitemen

How can I solve this problem?

Litisqe Kumar
  • 2,512
  • 4
  • 26
  • 40
  • 1
    It seems you have put very little research into this question. There are hundreds of questions on stack overflow on converting json to data objects. Look into using GSON for the parsing, retrofit for the network calls, and search json to pojo in google for a plethora of tools for converting json to a java object. – Elli White May 15 '15 at 15:03

1 Answers1

0

You should use JSONObject and get the elements you want from it. Take a look at this question : How to parse JSON in Android And this tutorial http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ or google it for other tutorials

Community
  • 1
  • 1
Gabriella Angelova
  • 2,985
  • 1
  • 17
  • 30