0

私はjsonが初めてなので、これを解決するのを手伝ってください

propertyAlerts: [
{
    alertDomain: "oiq.core.alert.PropertyAlert",
    alertType: "HERITAGE_DETECTED",
    oiqCreatedDate: "2013-11-04 03:06:26"
}]

javaを使用して、次のデータを取得したい

OUTPUT:
alertDomain: "oiq.core.alert.PropertyAlert"
alertType: "HERITAGE_DETECTED"
oiqCreatedDate: "2013-11-04 03:06:26"

以下は私が使用しています

public void checklicense(String filename) throws Exception
    {
JSONParser parser=new JSONParser();
Object obj = parser.parse(new FileReader("./output_profiles/"+filename));
JSONObject jsonObject = (JSONObject) obj;
JSONArray jsonMainArr = obj.getJSONArray("propertyalert"); 
JSONObject childJSONObject = jsonMainArr.getJSONObject(i);
     String alertDomain = childJSONObject.getString("alertDomain");

}

誰でもこの問題を解決するのを手伝ってくれますか

4

2 に答える 2

0
public static void checklicense(String filename) 
{
    try {
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader(filename));
        System.out.println(obj.getClass());
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray jsonMainArr = (JSONArray) jsonObject.get("propertyAlerts");
        Iterator iterator = jsonMainArr.iterator();
        while(iterator.hasNext()) {
            jsonObject =(JSONObject) iterator.next();
            String alertDomain = (String) jsonObject.get("alertDomain");
            String alertType = (String) jsonObject.get("alertType");
            System.out.println("alertDomain " + alertDomain + ", alertType " + alertType );
        }
    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(EosClient.class.getName()).log(Level.SEVERE, null, ex);
    } 
}

上記のコードは、有効な json 入力に必要な出力を生成します

{
"propertyAlerts": [
    {
        "alertDomain": "oiq.core.alert.PropertyAlert",
        "alertType": "HERITAGE_DETECTED",
        "oiqCreatedDate": "2013-11-04 03:06:26"
    }
]
}
于 2013-11-04T11:47:58.250 に答える