Gravity Gravity - 1 year ago 238
JSON Question

JSON Serialize Object Array Android

I have a very simple Object Array

Object[] args = new Object[] {"002"};

My goal is to JSON serialize this Object Array in Android and get the result as a byte array. There are two classes for JSON Serialization in Android.
. Which class should I use?

Spefically I am not sure how to use the

JSONObject json = new JSONObject();
json.put("key", "value");

routine in this case.

Answer Source

You should use a JSONArray for this

JSONArray jsonArray = new JSONArray();
byte[] bytes = jsonArray.toString().getBytes()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download