1

次のようなjsonデータがあります。

{ 
    "err_code": "0", 
    "date":"20130121",
    "time_from":"1242", 
    "range":"5",
    "data":[['12313123','BOOK CODE CYFV3M
NUM CODE 3789850802600'],['089898989','BOOK CODE 1F45MN
NUM CODE 3787510241500']] 
}

そして私はこのプログラムを試しました:

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonKAI {

    public static void main(String[] args) {

        String jStr = "{\"err_code\":\"0\",\"date\":\"20130121\",\"time_from\":\"1242\",\"range\":\"5\",\"data\":[['12313123','BOOK CODE CYFV3M NUM CODE 3789850802600'],['089898989','BOOK CODE 1F45MN NUM CODE 3787510241500']] }";
// Replace this try catch block for all below subsequent examples
        try {
            JSONObject rootObject = new JSONObject(jStr);
            JSONArray rows = rootObject.getJSONArray("data"); // Get all JSONArray data
            int count = rows.length();
            for(int i=0 ; i< count; i++){
                JSONArray jsonArr = rows.getJSONArray(i);
                System.out.println("jsonObject " + i + ": " + jsonArr);
                //for(int j=0 ; j< count; j++){
                //JSONArray jArr = rows.getJSONArray(j);
                //String s = jArr.toString();
                //System.out.println("jsonObject " +s);
            }}
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

出力は次のとおりです。

jsonObject 0: ["12313123","BOOK CODE CYFV3M NUM CODE 3789850802600"]
jsonObject 1: ["089898989","BOOK CODE 1F45MN NUM CODE 3787510241500"]

["12313123","BOOK CODE CYFV3M NUM CODE 3789850802600"] から取得/解析する方法を知りたい

to 12313123and BOOK CODE CYFV3M NUM CODE 3789850802600(without '[' and '"')? 助けてください. ありがとう.

4

2 に答える 2

1

あなたはこれを試すことができます:

        String jStr = "{\"err_code\":\"0\",\"date\":\"20130121\",\"time_from\":\"1242\",\"range\":\"5\",\"data\":[['12313123','BOOK CODE CYFV3M NUM CODE 3789850802600'],['089898989','BOOK CODE 1F45MN NUM CODE 3787510241500']] }";
        try {
          JSONObject rootObject = JSONObject.fromObject(jStr);
          JSONArray rows = rootObject.getJSONArray("data"); // Get all JSONArray data
          int count = rows.size();
          for (int i = 0; i < count; i++) {
            JSONArray jsonArr = rows.getJSONArray(i);
            System.out.println("jsonArray " + i + ": " + jsonArr);
            for (Object o : jsonArr) {          
              System.out.println(o);
            }
          }
        } catch (JSONException e) {
        }
于 2013-01-27T03:06:28.040 に答える