Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...