merging two json objects into single object in java

后端 未结 3 1940
有刺的猬
有刺的猬 2020-12-18 08:03

I have two json objects like below:

{\"name\":[\"Karbonn Smart A12 Star (Black & Silver)\",\"Nokia 220 (Black)\",\"Karbonn Smart A52 Plus (Black & Go         


        
3条回答
  •  渐次进展
    2020-12-18 08:41

    you can find org.json here JSON-java

    import java.util.ArrayList;
    import java.util.List;
    import org.json.*;
    
    public class JsonTest
    {   
        public String mergeJson(String name, String price)
        {
            JSONObject nameJ= new JSONObject(name);
            JSONObject priceJ= new JSONObject(price);
            JSONObject mobileJ = new JSONObject();
    
            JSONArray names = nameJ.getJSONArray("name");
            JSONArray prices = priceJ.getJSONArray("price");
            JSONArray mobiles = new JSONArray();
    
            if(names.length() == prices.length())
            {
                for(int i=0;i

提交回复
热议问题