Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

php - parsing a specific JSON data

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.

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

use this to make own model .

http://www.jsonschema2pojo.org/

after making model you can use bwlow code.

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

AddPostModel have all the data which comes from server.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...