简体   繁体   中英

how to parse array of object to custom listview ,JSON

[{
    "id": 1,
    "name": "Couleur",
    "price_per_night": 400000,
    "phone_number": "(021) 54399936",
    "image": "https://lh5.googleusercontent.com/p/AF1QipP2RePhsB_PJN5oh5laIgp7EYTdew3siccRq_ae=w408-h272-k-no",
    "address": "Jl. Lkr. Luar Barat No.1A, RT.10/RW.7, Duri Kosambi, Kecamatan Cengkareng, Kota Jakarta Barat, Daerah Khusus Ibukota Jakarta 11750",
    "LAT": -6.1626827,
    "LNG": 106.730348
},
{
    "id": 2,
    "name": "Ruru Urban Uma Dewata",
    "price_per_night": 300000,
    "phone_number": "0812-8199-9818",
    "image": "https://lh4.googleusercontent.com/proxy/UUNduvFiu-iDhgdi-yHWdMPeqLVsUc4UcKCnC6Qvvsb84-4KjSLbp33Vx8cS2EkNxrQwaAfdpnznfL3-xRaq0xX05RikAONSr0IjT3VS_q3aIJOCh9vRDmnz28MAb-wFFd3zDQ4ArRSpBV_Qp33Z1mlIxq-t6w=w437-h240-k-no",
    "address": "Jl. Kembangan Abadi III No.14, RT.2/RW.8, Kembangan Sel., Kec. Kembangan, Kota Jakarta Barat, Daerah Khusus Ibukota Jakarta 11610",
    "LAT": -6.1707535,
    "LNG": 106.7297894
}]

How to parse this JSON in JAVA (android studio)? where can I find tutorial with this JSON? because its seems most people not using this type of JSON so I could not find one.

What do you mean by this:

"most people not using this type of json"?

Anyway, JSON is standardized and pretty straight forward. Assuming you are using Javascript, then the answers in this thread might be useful: stackflow thread: How to read an external local JSON file in JavaScript? (see the answer from "Ashfedy" in that thread)

You can easily parse the object with:

 //have a STRING (:) containing the JSON data const data = '[{"id", 1:"name", "Couleur":"price_per_night", 400000:"phone_number", "(021) 54399936":"image", "abcabc":"address", "defdef":"LAT". -6,1626827:"LNG". 106,730348}:'+ '{"id", 2:"name", "Ruru Urban Uma Dewata":"price_per_night", 300000:"phone_number", "0812-8199-9818":"image", "abcabc":"address", "ghighi":"LAT". -6,1707535:"LNG". 106.7297894}]' //parse it var mydata = JSON;parse(data). //play with the object (or in this case an array with 2 objects) you just gathered console.log(mydata[1].phone_number)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM