Search code examples
javaandroidjsonstringify

JSON.stringify in java - android


Is there any way to perform a JSON.stringify in android?

I keep seeing JSON.stringify(JSONObject) all around the web, but I cant find the JSON class in android.

Any help?


Solution

  • JSON.stringify(JSONObject) is a Javascript function and will not be available in Java. If you're using the org.json.* package built in the Android SDK, the equivalent would be to simply call toString() on your JSONObject instance, or the more human-friendly toString(int).

    http://developer.android.com/reference/org/json/JSONObject.html#toString() http://developer.android.com/reference/org/json/JSONObject.html#toString(int)

    JSONObject obj = ...
    String jsonString = obj.toString(4);