Mongo DB에서 추출한 JSONObject를 구문 분석하고 있습니다. 숫자 값은 설명서에 따라 java.lang.number 객체에 매핑됩니다. 그러나 먼저 다음 코드를 만들려고하면 오류가 발생합니다. System.out.println(value.floatVlaue())
.JSONObject를 파싱하고 있지만 NullPointer 예외로 실행 중
//For data
int counter = 0;
float score = 0;
Number value = 0;
while(cur.hasNext()){
JSONObject jsonObj = (JSONObject) JSONValue.parse(cur.next().toString());
metricsIterator = ((JSONObject)((JSONObject)((JSONObject)((JSONObject)jsonObj.get("level_1")).get("level_2")).get("level_3")).get("metrics")).keySet().iterator();
while(metricsIterator.hasNext()){
System.out.println(metricsIterator.next().toString());
value = (Number) jsonObj.get(metricsIterator.next());
System.out.println(value.floatValue());
System.out.println(value.toString());
someLogic(value.doubleValue(), ((Number)jsonObj.get("long")).intValue(), start, end, days);
}
}
나는 문제 라인은 확실히 JSON 메신저 구문 분석 전혀 도움을 너무 많이이
{ "_id" : "9223370663181869423_cnn_1" ,
"long" : 1373672925000 ,
"level_1" :
{ "level_2" :
{ "level_3level" :
{ "metrics" :
{"key1" : 0.003333333333333334 ,
"key2" : 0.005833333333333334 ,
"key3" : 0.005833333333333334 ,
"key4" : 0.009166666666666667 ,
"key5" : 0.1391666666666667 ,
"key6" : 0.1241666666666667 ,
"key7" : 0.01666666666666667
}
}
}
}
}
감사처럼 보이는 value = (Number) jsonObj.get(metrics Iterator.next())
에서 오는 것 같아요!