Skip to content
Advertisement

Why JSONObject converts stringified array to JSONArray on put operation? How to stop this?

  • When I tried to put stringified array in JSONObject, it became a JSONArray. But I want to keep the stringified array. Any help will be appreciated.

eg:

JavaScript

So, when I debugged it, the jsonObj properties were

JavaScript

Edit: Here is the link for sample code: https://onlinegdb.com/UbV6VXvpJ. Code won’t compile due to missing packages in online ide, just for better understanding of scenario I have added the link.

Advertisement

Answer

Here is why, if you look at the declaraction of constructor of JSONObject, you will find what you are looking for. One of the constructor of JSONObject class looks like following:

JavaScript

If you know how to do reverse engineering, you should be able to find more about the actual implementation :)!

Hopefully, this will help you out!

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement