PHP経由でMySql DBから情報を取得しています。情報は、次の JSON 配列で返されます。
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
ます。情報が返されたので、そこに含まれる個々の文字列/整数を解析して、ローカルの sqlite データベースに配置します。
これが問題の2行です
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.
返された情報を個々の文字列と整数に変換して、次のコード行で使用できるようにするにはどうすればよいですか? いくつかのリソースへの指示は非常に役立ちます。
アップデート
上記の 2 行のコードの間に次の行を追加しました。出力は null ポインター例外です。
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();
}