Reputation: 311
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. JSONArray
and JSONObject
. 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.
Upvotes: 2
Views: 779
Reputation: 129
You should use a JSONArray for this
JSONArray jsonArray = new JSONArray();
jsonArray.put("002");
byte[] bytes = jsonArray.toString().getBytes()
Upvotes: 1