android 多个类的对象,如何从Android中的URL解析多个JSON对象和数组...

我想在服务器端进行以下编辑

我跟随this的例子

但在那边他正在从url用一个json对象调用数据

叫做“世界人口”

但是我有一个Json数据,其中包含很多Json对象和数组,..如下代码所示

{ "getting data":"ok"

"Todays":population

{"results"{[

"worldpopulation":

[

{

"rank":1,"country":"China",

"population":"1,354,040,000",

"flag":["http://www.androidbegin.com/tutorial/flag/china.png"]

},

{

"population":{

[

"countrypulation" {

"rank":2,"country":"India",

"population":"1,210,193,422",

"flag":["http://www.androidbegin.com/tutorial/flag/india.png"]

},

像这样,我有很多数据,在上面的示例中我想要这些数据.无需更改服务器端的任何内容或静态服务.

谢谢

最佳答案

响应

JSONObject JObject = new JSONObject(response);

String getting_data = JObject.getstring("getting data");

String Todays= JObject.getstring("Todays");

JsonArray results =JObject.getjsonarray("results");

for(int i = 0 ; i < results.length(); i++){

JsonObject resultsobject =results.getjsonobject(i);

JsonArray worldpopulation

=resultsobject.getjsonarray("worldpopulation");

for(int j = 0 ; j < worldpopulation.length(); j++){

JsonObject worldpopulationobject =worldpopulation.getjsonobject(j);

JsonObject emptyobject =worldpopulationobject.getjsonobject("");

String rank=emptyobject .getstring("rank");

String population=emptyobject .getstring("population");

JsonArray flagarray =countrypulation.getjsonarray(flag);

for(int n = 0 ; n < flagarray.length(); n++){

JsonObject flagarrayobject =flag1array.getjsonobject(n);

String flag=flag1arrayobject .getstring("flag");

}

JsonObject populationobject

=worldpopulationobject.getjsonobject("population");

JsonArray emptyarray =JObject.getjsonarray("");

for(int k = 0 ; k < emptyarray.length(); k++){

JsonObject emptyarrayobject =emptyarray.getjsonobject(k);

JsonObject

countrypulation=emptyarrayobject.getjsonobject("countrypulation");

String rank1=countrypulation .getstring("rank");

String country=countrypulation .getstring("country");

String population1=countrypulation .getstring("population");

JsonArray flag1array =countrypulation.getjsonarray(flag);

for(int m = 0 ; m < flag1array.length(); m++){

JsonObject flag1arrayobject =flag1array.getjsonobject(m);

String flag1=flag1arrayobject .getstring("flag");

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值