如果json字符串没有键名,则无法使用Gson解析json

时间:2016-08-19 05:53:16

标签: android json gson

我有json字符串,但无法解析。谁能帮忙。提前谢谢。

{
  [ 
    {"transaction_name" : "total_fare", "unit" : "Rs", "label" : "Bill Amount", "value" : 250, "additional_details" : "4 Rides"}, 
    {"transaction_name" : "incentives", "label" : "Incentives", "value" : 50, "additional_details" : ""},
    {"transaction_name" : "fees", "label" : "Fees", "value" : -20, "additional_details" : "Rs 5 on each ride"},
    {"transaction_name" : "device_deduction", "label" : "Device Deduction", "value" : -20, "additional_details" : ""},
    {"transaction_name" : "tax", "label" : "Device Deduction", "value" : -20, "additional_details" : ""},
    {"transaction_name" : "device_deduction", "label" : "Device Deduction", "value" : -20, "additional_details" : ""}]
  ],
  "footer" : 
    {
      "transaction_name" : "total_earning_net", "label" : "Total Earnings", "value" : 200, 
      "additional_details" : "Rounding Off"
    }
}

1 个答案:

答案 0 :(得分:0)

您的JSON本身是错误的,请尝试为您的JSONArray提供密钥,

{
"data": [{
    "transaction_name": "total_fare",
    "unit": "Rs",
    "label": "Bill Amount",
    "value": 250,
    "additional_details": "4 Rides"
}, {
    "transaction_name": "incentives",
    "label": "Incentives",
    "value": 50,
    "additional_details": ""
}, {
    "transaction_name": "fees",
    "label": "Fees",
    "value": -20,
    "additional_details": "Rs 5 on each ride"
}, {
    "transaction_name": "device_deduction",
    "label": "Device Deduction",
    "value": -20,
    "additional_details": ""
}, {
    "transaction_name": "tax",
    "label": "Device Deduction",
    "value": -20,
    "additional_details": ""
}, {
    "transaction_name": "device_deduction",
    "label": "Device Deduction",
    "value": -20,
    "additional_details": ""
}],
"footer": {
    "transaction_name": "total_earning_net",
    "label": "Total Earnings",
    "value": 200,
    "additional_details": "Rounding Off"
  }

}