2013-08-02 58 views
-4

我JSON响应这样的:无法解析JSON数组内JSON阵列

{ 
    "ResponseCode": "000", 
    "ResponseDescription": "Successful", 
    "ResponseData": [ 
    [ 
     "RequestID", 
     "ProviderAuditID", 
     "RequestTime", 
     "Product", 
     "ProductCode", 
     "Currency", 
     "Value", 
     "ValueRes", 
     "ValuePro", 
     "TransactionResponseCode", 
     "TransactionResponseDescription" 
    ], 
    [ 
     "23", 
     null, 
     "2013-07-22 07:09:06", 
     "Test Product", 
     "098", 
     "India", 
     "456.000000", 
     "456.000000", 
     "456.000000", 
     null, 
     null 
    ], 
    ] 
} 

现在我要分析此值,并将其设置到列表视图,以便 谁能帮助我如何实现这一目标???

编辑::

我在解析的多重价值,这只是一个例子...

+0

您可能需要使用多个foreach循环 –

+0

这是使用JSON非常糟糕的做法。 –

+0

那你想用它做什么? Instanciate具有相同属性的类? Juste显示数据? – Oyashiro

回答

2

您有在字段中的一个阵列的包装对象。该字段包含一个字符串列表。

解析你的JSON转换成一个JSONObject,那么你可以简单地得到您的JSONArray,并得到里面的列表。

这应该工作:

JSONObject response = new JSONObject(json); 
JSONArray jsonArray = response.getJSONArray("ResponseData"); 
for (int i = 0; i < jsonArray.length(); i++) { 
    JSONArray arrValues = (JSONArray) jsonArray.get(i); 
    // do what you have to do with the values 
    for (int i = 0; i < arrValues.length(); i++) { 
     String value = (String) arrValues.get(i); 
    } 
} 
+0

它可能工作但是我检查AndroidLearner的JSON在http://jsonlint.com/其错误 –

+0

这是错误的,后面的逗号,可能是因为他抄错了。 – Enrichman

+0

@Enrichman'列表 myList中=(列表)jsonArray.get(I);'这条线显示我'java.lang.ClassCastException:org.json.JSONArray'。 – AndroidLearner

1

请检查您的JSON数据。使用 以下网站 - http://jsonlint.com/

您的JSON是无效的。

+0

我已经签了JSON在JSONLINT,其100%vaild .. – AndroidLearner

+0

请检查我在你的JSON字符串歌厅错误。 – Hemant

+0

这不是有效的JSON。特别是在倒数第三行后面的逗号是无效的。 – dpjanes