java - Android convert JSONArray to String Array -


I get data from Jason and have a Jason array. I want to change that Jason array to string array, so I I can send it to another activity and show it in the ListView .

Here is my Java code

  if (jsonStr! = Null) {try {foodsFilter = new JSONArray (jsonStr); // Looping for all contacts (int i = 0; i & lt; foodsFilter.length (); i ++) {JSONObject c = foodsFilter.getJSONObject (i); If (c.getString ("category_name"). Equals ("food")) {string category_name = c.getString (TAG_CATEGORY_NAME); String filter_type = c.getString (TAG_FILTER_TYPE); // string item_list = c.getString (TAG_ITEM_LIST); JSONArray Item List = New JSONArray (c.getString ("item_list")); String item_list = itemList.toString (); // TMP Hashpe Hashmap for Single Contact   

I try that code to replace JSONarray , but I realized that the code JSONArray is passed to Is to convert to string .

JSON data

  here [{"category_name": "food", "filter_type": "sort", "field_name" : "Code": "VALUE", "table_name": "", "item_list": ["ascending", "descending"]}]   

Item_list want to change the array like this

  item_list = {"ascending", "descending"}   

Can send any other activity in the intent and show it in ListView

what do you have

  string item_list = ite MList.toString ();   

You need to parse items_list which is JSONArray .

  JSONArray item list = New JSONArray (c.getString ("item_list")); // Get loop and list through array item (int i = 0; i & lt; itemList.length (); i ++) {string item = itemList.getString (i); // item on the index i}   

Now you can add a string to a list / array and after that it may be necessary.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -