java替换string值变更为JSONObject或JSONArray方法

来源:互联网 发布:玩淘宝要费多少流量 编辑:程序博客网 时间:2024/06/08 18:06
for(inti= 0;i<jsonArray.size();i++) {
              Stringrep=jsonArray.get(i).toString();
              Stringreplace="";
              Stringcity="\"city\":";
              Stringsum="\"detailsum\":";
              Stringreward="";
              replace=rep.replace("[","").replace("]","");
              String[]sp=replace.split(",");
              Stringre1=city+sp[0].toString();
              Stringre2=sum+sp[1].toString();
              reward="{"+re1+","+re2+"}";
              JSONObjectjsonObject= JSONObject.fromObject(reward);
            //JSONArrayjsonarray= JSONArray.fromObject(actinfo);

              jsonArray.set(i,jsonObject);
          }

通过以上方法可以将string取出然后化为单独jsonobject或jsonarray类型
0 0