解析一个特定的JSON数据 [英] parsing a specific JSON data

查看:121
本文介绍了解析一个特定的JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个Android应用程序ñ使用PHP文件以调用返回我JSON输出,现在我的问题是输出是一个有效的JSON格式的Java脚本文件,但我很困惑,如何解析值。输出

i am making a android application n use a .php file to call java script file that returns me a JSON output, now my problem is the output is in a valid JSON format, but i am confused as to how to parse the values. the output is

{
   "destination_addresses" : [
  "Kambarganvi road, Durgadakeri, Karnataka 580011, India",
  "St Inez Road, Santa Inez, Panjim, Goa 403001, India",
  "Dr Braganza Pereira Road, Santa Inez, Panjim, Goa 403001, India",
  "Dayanand Bandodkar Marg, Santa Inez, Panjim, Goa 403001, India",
  "St Inez Road, Santa Inez, Panjim, Goa 403001, India",
  "18th June Road, Santa Inez, Panjim, Goa 403001, India"
   ],
   "origin_addresses" : [ "Suyog Residency, St Joaquim Road, Borda, Margao, Goa 403602, India" ],
"rows" : [
  {
     "elements" : [
        {
           "distance" : {
              "text" : "133 km",
              "value" : 132717
           },
           "duration" : {
              "text" : "1 day 4 hours",
              "value" : 100199
           },
           "status" : "OK"
        },
        {
           "distance" : {
              "text" : "33.4 km",
              "value" : 33427
           },
           "duration" : {
              "text" : "6 hours 54 mins",
              "value" : 24832
           },
           "status" : "OK"
        },
        {
           "distance" : {
              "text" : "33.5 km",
              "value" : 33518
           },
           "duration" : {
              "text" : "6 hours 55 mins",
              "value" : 24923
           },
           "status" : "OK"
        },
        {
           "distance" : {
              "text" : "33.8 km",
              "value" : 33834
           },
           "duration" : {
              "text" : "7 hours 0 mins",
              "value" : 25170
           },
           "status" : "OK"
        },
        {
           "distance" : {
              "text" : "33.5 km",
              "value" : 33503
           },
           "duration" : {
              "text" : "6 hours 55 mins",
              "value" : 24893
           },
           "status" : "OK"
        },
        {
           "distance" : {
              "text" : "33.5 km",
              "value" : 33457
           },
           "duration" : {
              "text" : "6 hours 55 mins",
              "value" : 24880
           },
           "status" : "OK"
        }
     ]
  }
],
"status" : "OK"
}

我想解析以这样的方式,我可以将结果的距离应放在数据结构等的阵列,然后这些值进行排序。

i want to parse the values in such a way that i can place the distances of the result should be put in a data structure like an array and then sort them.

谢谢你在前进。

推荐答案

使用此做出自己的模型。

use this to make own model .

http://www.jsonschema2pojo.org/

造模后,您可以使用bwlow code。

after making model you can use bwlow code.

Gson gson = new Gson();
gson.fromJson(jData, AddPostModel.class);

AddPostModel有所有这些来自服务器的数据。

AddPostModel have all the data which comes from server.

这篇关于解析一个特定的JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆