我想知道如何通过j sons获取数据。我是这样创造但没有得到任何数据?
"arr": [1]
0: {
"obj": {
"id": "24"
"dispensary_id": "24"
"item_name": "item 3"
"total_feedback": "1"
"total_item": "13"
"followers": "7"
"follow_status": "following"
"category": "Edibles"
"strain": "Indica"
"tch": "0.70"
"cbd": "13.30"
"description": "testing items"
"image": "1447508911_greenfeed-3.jpg"
"qty1": "1/8 OZ"
"price1": "100"
"qty2": "1/4 OZ"
"price2": "200"
"qty3": "1/2 OZ"
"price3": "400"
"qty4": "1 OZ"
"price4": "799"
"dispensary_first_name": "Acme Dispensary"
"dispensary_last_name": "Smith"
"company": "Acme Dispensary"
"dispensary_image": "1449182412.png"
"city": "Irvine"
"state": "CA"
"status": "1"
}-
}-
-
"result": "true"
}
答案 0 :(得分:0)
使用gson库解析JSON数据。要了解如何使用它,请使用此链接http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html
答案 1 :(得分:0)
你的JOSN格式错了它应该是这样的
{
"obj": {
"id": "24",
"dispensary_id": "24",
"item_name": "item 3",
"total_feedback": "1",
"total_item": "13",
"followers": "7",
"follow_status": "following",
"category": "Edibles",
"strain": "Indica",
"tch": "0.70",
"cbd": "13.30",
"description": "testing items",
"image": "1447508911_greenfeed-3.jpg",
"qty1": "1/8 OZ",
"price1": "100",
"qty2": "1/4 OZ",
"price2": "200",
"qty3": "1/2 OZ",
"price3": "400",
"qty4": "1 OZ",
"price4": "799",
"dispensary_first_name": "Acme Dispensary",
"dispensary_last_name": "Smith",
"company": "Acme Dispensary",
"dispensary_image": "1449182412.png",
"city": "Irvine",
"state": "CA",
"status": "1"
}
}
为此您可以检查您的json是否有效http://jsonlint.com/
用于创建json,你可以使用像
这样的库JSONObject jsonObject = new JSONObject();
jsonObject.add("key", "value");
jsonObject.add("key", "value");