Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to transform arraylist to json array in java

JSONObject jsonObject = new JSONObject();
    try {
 
      //Settings up array
      JSONArray jArry = new JSONArray();
    
      //this arraylist is contains of arraylist with tagIDs
      ArrayList<InventoryListItem> arr = Application.tagsReadInventory;
    
      int position = 0;
    
      //this arraylist is where i put my collected tagIDs from "Application.tagsReadInventory"
      ArrayList<String> tagIDs = new ArrayList<>();
  
      //looping to get tagIDs from "Application.tagsReadInventory" and put it in tagIDs arraylist
       for (position = 0; position < arr.size(); position++) {                        
           tagIDs.add(arr.get(position).getTagID());
       }
    
       //get each of the list inside tagIDs arraylist
       for (String tags : tagIDs) {
           JSONObject jObj = new JSONObject();
           jObj.put("epc",tags);
           jObj.put("antennaPort", 1);
           jArry.put(jObj);
       }
    
     jsonObject.put("reader_name", ReaderIP);
     jsonObject.put("mac_address", "asd");
     jsonObject.put("tag_reads", jArry);
    
  } catch (JSONException e) {
        e.printStackTrace();
  }
Comment

arraylist to json array

ArrayList<String> list = new ArrayList<String>();
list.add("foo");
list.add("baar");
JSONArray jsArray = new JSONArray(list);
Comment

PREVIOUS NEXT
Code Example
Javascript :: phoenix routes 
Javascript :: js create jaon object from for loop 
Javascript :: javascript array loop back 
Javascript :: js Changing selected option by option text 
Javascript :: range between two numbers 
Javascript :: activate router angular 
Javascript :: js access sql database on server 
Javascript :: macam macam looping javascript 
Javascript :: dual array in javascript 
Javascript :: is already declared javascript 
Javascript :: read more/less button with smoth expand 
Javascript :: jquery-3.5.1.min.js download 
Python :: pygame disable message 
Python :: pandas read tsv 
Python :: conda install ffmpeg 
Python :: python pip install matplotlib 
Python :: pygame scale image python 
Python :: how to make a letter animation in python 
Python :: how to return PIL image from opencv 
Python :: python measure time 
Python :: create python alias for python3 
Python :: pip install error 
Python :: how to add legend to python plot 
Python :: select first word in string python 
Python :: accuracy score sklearn syntax 
Python :: get common elements from two lists 
Python :: renaming headers pandasd 
Python :: how to check weather my model is on gpu in pytorch 
Python :: get python directiory 
Python :: how to install mediapipe python 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =