私はこのようなJSON応答を持っています::
{
"ResponseCode": "000",
"ResponseDescription": "Successful",
"ResponseData": [
[
"RequestID",
"ProviderAuditID",
"RequestTime",
"Product",
"ProductCode",
"Currency",
"TopUpValue",
"TopUpValueRes",
"TopUpValuePro",
"TransactionResponseCode",
"TransactionResponseDescription"
],
[
"94",
"663",
"2013-08-02 07:02:54",
"Test 1",
"2222",
"IND",
"700.000000",
"700.000000",
"700.000000",
"000",
"Successful"
],
[
"93",
"661",
"2013-08-02 06:21:13",
"Test 2",
"5555",
"IND",
"160.000000",
"160.000000",
"160.000000",
"000",
"Successful"
]
]
}
以下のメカニズムを使用して、この JSON を正常に解析しました::
final JSONObject jsonObject=new JSONObject(response);
if(jsonObject.getString("ResponseCode").equals("000"))
{
System.out.println("%%%% m inside....");
JSONArray jArray = jsonObject.getJSONArray("ResponseData");
System.out.println(" &&&&&&& ====>"+jArray.length());
for (int i = 0; i < jArray.length(); i++)
{
JSONArray arrValues = (JSONArray) jArray.get(i);
System.out.println(" &&&&&&& Arr ====>"+arrValues);
for (int j = 0; j < arrValues.length(); j++)
{
String value = (String) arrValues.get(j);
System.out.println(" &&&&&&& ArrValues====>"+value);
}
}
}
ログ応答 :::
Arr ====>["RequestID","ProductType","RequestType","ProviderAuditID","RequestTime","Product","ProductCode","Currency","Batch","ReferenceNumber","TopUpValue","TopUpValueRes","TopUpValuePro","TransactionResponseCode","TransactionResponseDescription"]
ArrValues====>RequestID
ArrValues====>ProductType
ArrValues====>RequestType
ArrValues====>ProviderAuditID
ArrValues====>RequestTime
ArrValues====>Product
ArrValues====>ProductCode
ArrValues====>Currency
ArrValues====>Batch
ArrValues====>ReferenceNumber
ArrValues====>TopUpValue
ArrValues====>TopUpValueRes
ArrValues====>TopUpValuePro
ArrValues====>TransactionResponseCode
ArrValues====>TransactionResponseDescription
Arr ====>["381","1","2","662","2013-08-02 07:01:08","Test 1","7878","IND","Test 1","12121212121","1600.000000","1600.000000000000","1600.000000","000","Successful"]
ArrValues====>381
ArrValues====>1
ArrValues====>2
ArrValues====>662
ArrValues====>2013-08-02 07:01:08
ArrValues====>Test 1
ArrValues====>7878
ArrValues====>IND
ArrValues====>Test 1
ArrValues====>12121212121
ArrValues====>1600.000000
ArrValues====>1600.000000000000
ArrValues====>1600.000000
ArrValues====>000
ArrValues====>Successful
Arr ====>["380","0","1","657","2013-08-02 06:00:46","Test 1","9696","IND","Test 1","1234","900.000000","900.000000000000","900.000000","000","Successful"]
ArrValues====>380
ArrValues====>0
ArrValues====>1
ArrValues====>657
ArrValues====>2013-08-02 06:00:46
ArrValues====>Test 2
ArrValues====>9696
ArrValues====>IND
ArrValues====>Test 2
ArrValues====>1234
ArrValues====>900.000000
ArrValues====>900.000000000000
ArrValues====>900.000000
ArrValues====>000
ArrValues====>Successful
望ましいアウトプット :::
RequestID :: 381
Product :: Test 1
Currency :: IND
TransactionResponseDescription :: Successful
RequestID :: 380
Product :: Test 2
Currency :: IND
TransactionResponseDescription :: Successful
編集 ::
データを保存する際の問題は、リクエスト ID または製品の配列全体を取得できないことです。最初の配列ではすべてのヘッダー (ラベル) を取得し、残りの配列では値を取得しました。
したがって、0番目のインデックスでは常に RequestID を取得していることがわかります。では、目的の出力を達成するために値を保存する方法は?