日々精進

新しく学んだことを書き留めていきます

AndroidでJSONをparseする

普通はjacksonとか使うんだろうけど、処理するjsonが綺麗に構造化されていないので自分でparseすることにした。 JSONObjectを使うと文字列をparseしてdictionaryのような構造にしてくれる。

try {
    JSONObject responseJSON = new JSONObject(response);
} catch (JSONException e) {
    e.printStackTrace();
}

boolean success = responseJSON.getBoolean("Success");
String message = responseJSON.getString("Message");

参考: