2014-04-24 35 views
-1

我正在制作一个android应用程序n使用.php文件来调用返回给我一个JSON输出的java脚本文件,现在我的问题是输出是有效的JSON格式,但我很困惑如何解析这些值。输出是解析特定的JSON数据

{ 
    "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" 
} 

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

谢谢您提前。

+0

使用'json_decode':http://php.net/json_decode – Fracsi

+0

遵循该答案http://stackoverflow.com/questions/23259638/responsewrong-user-registration-via-android-app-using-http-post - 未加工/ 23259970#23259970 –

回答

0

使用它来制作自己的模型。

http://www.jsonschema2pojo.org/

造模后,您可以使用bwlow代码。

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

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