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 :: jquery get 2 hours frmo now 
Javascript :: javascript redirect with extra url arguments 
Javascript :: promise.all vs promise.allsettled 
Javascript :: moment.add 
Javascript :: vuejs get value of checkbox group 
Javascript :: set input value vanilla js 
Javascript :: node path relative 
Javascript :: send x-www-form-urlencoded request nodejs 
Javascript :: begins_with node js AWS dynamodb sort key 
Javascript :: chunk an array 
Javascript :: searching in json array mongodb 
Javascript :: set cookie using nest js 
Javascript :: Send Post Fetch REquest With Django 
Javascript :: how to delete duplicate elements in an array in javascript 
Javascript :: discord.js start code 
Javascript :: reset form input react 
Javascript :: get odd elements of list javascript 
Javascript :: javascript whitespace strip 
Javascript :: BREAK A LINE on JS 
Javascript :: react i18n outside component 
Javascript :: node js connect to mongodb using mongoose 
Javascript :: js get json object keys 
Javascript :: concatenate multiple arrays javascript 
Javascript :: how to remove an class in javascript 
Javascript :: how to stop re rendering in react 
Javascript :: js map through array and return array of objects 
Javascript :: mapdispatchtoprops 
Javascript :: editor js to html 
Javascript :: use location hook 
Javascript :: js check if a variable is an array 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =