SORU
7 NİSAN 2010, ÇARŞAMBA


Nasıl Java JSON ayrıştırma

*2, *, post_id, **3 vb almak için ayrıştırmak için gereken aşağıdaki JSON metin var.

Gerekli kod nedir?

{
   "pageInfo": {
         "pageName": "abc",
         "pagePic": "http://example.com/content.jpg"
    }
    "posts": [
         {
              "post_id": "123456789012_123456789012",
              "actor_id": "1234567890",
              "picOfPersonWhoPosted": "http://example.com/photo.jpg",
              "nameOfPersonWhoPosted": "Jane Doe",
              "message": "Sounds cool. Can't wait to see it!",
              "likesCount": "2",
              "comments": [],
              "timeOfPost": "1234567890"
         }
    ]
}

CEVAP
25 EYLÜL 2013, ÇARŞAMBA


org.json kütüphane kullanımı kolaydır. Örnek kod aşağıda:

import org.json.*;


JSONObject obj = new JSONObject(" .... ");
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts");
for (int i = 0; i < arr.length(); i  )
{
    String post_id = arr.getJSONObject(i).getString("post_id");
    ......
}

Ekstra örnekler bulabilirsiniz: Parse JSON in Java

İndirilebilir kavanoz: http://mvnrepository.com/artifact/org.json/json

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Fubar Protocol

    Fubar Protoc

    21 AĞUSTOS 2010
  • TantalizingTrance

    TantalizingT

    15 ŞUBAT 2009
  • UKF

    UKF

    2 Aralık 2009