[answered] How to convert JSONObject to string without files?

I have a JSON object. I want to convert it to a single string. Right now, the only method for doing this in my mind is using the saveJSONObject(…) function which saves it as a text file, and then reading that file.

However, I want to do it in without using the hard drive, as I happen to have a lot of JSON objects, and saving then reading each one of those would probably tax the hard drive, and my time waiting for it to finish doing so.

There is probably some simple function I’m not aware of that would do this process in a simple way.
And I could probably just write a function that does that myself, however turning all of those special symbols into \n \t \u043c and other tags is something that daunts me a little bit, so I want to rely on someone else’s solution that would probably handle all of those tags better than I could.

1 Like

If the JSON object is called json then you can get the string representation with
String s = json.toString();

5 Likes

This works well. As I said, there’s probably a simple function I’m not aware of.

Thanks a lot!