android object to json string code example
Example 1: object to json string android
Gson gson = new Gson();
String json = gson.toJson(myObj);
Example 2: string to JSONobject + android
String json = {"phonetype":"N95","cat":"WP"};
try {
JSONObject obj = new JSONObject(json);
Log.d("My App", obj.toString());
} catch (Throwable t) {
Log.e("My App", "Could not parse malformed JSON: \"" + json + "\"");
}