PHP를 통해 MySql DB로부터 정보를 얻고 있습니다. 정보는 다음 JSON 배열에 반환됩니다구문 분석 JSON 개별 문자열/int에 대한 문자열 배열
06-15 15:20:17.400: E/JSON(9865): {"tag":"get_game_state","success":1,"error":0,"GameState":{"monster":"Troll","qty":"1","exp":"0"}}
json으로 구문 분석되고 문자열 StringBuilder
를 사용하여 구축된다. 이제 나는 정보를 가지고 개별 문자열/ints에 대해 로컬 sqlite db에 넣으려는 구문을 분석하려고합니다. 여기
userFunctions.getServerGameState(email, monster, qty, exp); //this line gets the JSON array and the above information is returned
db.saveLocalGameSate(monster, qty, exp); //this line should take that information take String monster int exp and int qty and put them in the local db.
질문
의 두 줄입니까? 어떤 자원에 대한 어떤 방향이라도 도움이 될 것입니다.업데이트 I 코드의 두 개의 상기 라인 inbetween 다음 줄을 추가
는 출력 실제로 JSON 배열 아니다 널 포인터 예외
try {
JSONArray arr = new JSONArray(GameState);
JSONObject jObj = arr.getJSONObject(0);
String virtumon = jObj.getString("monster");
Integer qty = jObj.getInt("qty");
Integer exp = jObj.getInt("exp");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
이것을 가져 주셔서 감사합니다. 반환되는 JSONObject가 userFunctions 클래스에서 정확합니다. 몇 가지 조사를 수행하고 편집 된 정보를 추가했습니다. 올바른 방향으로 나아가는 단계라고 생각하십니까? – KDEx