如何解析android中的Json对象

时间:2015-05-15 14:58:34

标签: android json

我从Web服务获得了这个Json代码,我想提取属性Adventurousness,Artistic interest,“Emotionality,Imagination and”Intellect“的值”百分比“。这是我的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

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您应该使用JSONObject并从中获取所需的元素。看看这个问题:How to parse JSON in Android 本教程http://www.androidhive.info/2012/01/android-json-parsing-tutorial/或谷歌搜索其他教程