2015-02-11 17 views
0

我想以json的形式將數據從drupal網站發送到android應用程序。我已經創建了鏈接,現在我的鏈接正在以這種形式返回數據。 我不知道如何解析這個格式化的數據顯示在Android應用程序的列表視圖。如何解析從drupal站點到android應用程序的json數據?

{ 
    "nodes" : [ 
    { 
     "node" : { 
     "title" : "Saksham Iron Store", 
     "Contact" : "09216630565", 
     "Category" : "Decoration & Hardware", 
     "City" : "Sangrur" 
     } 
    }, 
    { 
     "node" : { 
     "title" : "Loaffer Hut Garments", 
     "Contact" : "8591697698", 
     "Category" : "Fashion & Garments", 
     "City" : "Sangrur" 
     } 
    }, 
    { 
     "node" : { 
     "title" : "BCB English Academy and Visa Guidance", 
     "Contact" : "8699010091", 
     "Category" : "Education", 
     "City" : "Sangrur" 
     } 
    }, 
    { 
     "node" : { 
     "title" : "Aggarwal Engineering Corporation", 
     "Contact" : "9417070197", 
     "Category" : "Decoration & Hardware", 
     "City" : "Sangrur" 
     } 
    }, 
    { 
     "node" : { 
     "title" : "Inder Sain Paint and Decoration", 
     "Contact" : "9888821904", 
     "Category" : "Decoration & Hardware", 
     "City" : "Sangrur" 
     } 
    } 
    ] 
} 

我該如何解析它並在android應用程序的listview中顯示?

+0

你的問題應該是「如何在Android中解析JSON?」 – Raptor 2015-02-11 10:03:18

+0

[How to parse JSON in Android](http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) – Raptor 2015-02-11 10:03:37

+0

格式不同 [ { 「 vehicleType「: 」挖掘機「, 」vehicleColor「: 」黃「, 」燃料「: 」柴油「, 」approvedOperators「: [ { 」名稱「: 」格雷格斯塔克「, 」experiencePoints「:13 },{ 「名」: 「阿爾蒂帕特爾」, 「experiencePoints」:21 },{ 「名稱」: 「塔裏克米贊」, 「experiencePoints」:9 } ], 「treadType」: 「板鏈」 }, 「treadType」: 「車輪」 } ] – 2015-02-11 10:19:43

回答

0

假設接收數據的JSON語法符合標準模型,您可以使用org.json包中已存在的庫之一(例如,數組爲JSONArray)解析JSON。

我建議你看看GSON庫(我個人偏好,當然還有其他很多),因爲它更容易專注於業務邏輯,而不會因爲解析JSON而佔用你自己。

相關問題