本文目錄一覽:
json如何拼接
main()
{ long int m9=9,sum=9;
int zi,n1=1,c9=1;
scanf(“%d”,zi);
while(n1!=0)
{ if(!(sum%zi))
n1=0;
else
{m9=m9*10;
sum=sum+m9;
c9++;
}
}
printf(“%ld,can be divided by %d \”9\””,sum,c9);
}
怎麼自己拼接一個json格式
方法,整個json串是一個listmap或者Map,然後Map中又可以添加Map,也可以添加ListMap ,如此層層添加即可。
因此,只使用List和Map操作,就可以拼接任意固定格式的Json字符串。
java代碼:
String inputJson = “”;Map inputMap = new HashMap();
// userMap userMap = new HashMap();userMap.put(“loginName”, “));userMap.put(“loginPassword”,”));inputMap.put(“userInfo”, userMap);
// dataMap bussdataMap = new HashMap();bussdataMap.put(“tableName”, “”);ListMap dataList = new ArrayListMap();Map dataMap = new HashMap();
// dataMap.put(“id”, “”);dataMap.put(“id_card_no”,”” );dataList.add(dataMap);bussdataMap.put(“row”, dataList);inputMap.put(“dataInfo”, bussdataMap);
// operationTypeinputMap.put(“operate”, “插入”);JSONWriter writer = new JSONWriter(false);inputJson = writer.write(inputMap);
兩個json二維數組怎麼,進行拼接
如果兩個json字段相同,拼接起來的話 後一個json會覆蓋前一個json的字段。
如果想保留2個json的數據 就把這2個json放到一個數組裡吧。
分別給出代碼:
拼接,字段相同會覆蓋:
script type=”text/javascript”var j1 = { ”: ”, action: ‘adduser’, user: ‘123’, pwd: ‘11111’, rpassword: ‘11111’, email: ‘3@163.com’ }var j2 = { aa:’aa’, user: ‘user’}json = eval(‘(‘+(JSON.stringify(j1)+JSON.stringify(j2)).replace(/}{/,’,’)+’)’);console.log(json); /script
不覆蓋,放到一個數組裡:
script type=”text/javascript”var j1 = { ”: ”, action: ‘adduser’, user: ‘123’, pwd: ‘11111’, rpassword: ‘11111’, email: ‘3@163.com’ }var j2 = { ”: ‘222’, action: ‘adduser222’, user: ‘123222’, pwd: ‘11111222’, rpassword: ‘11111222’, email: ‘32222@163.com’ }json = [j1,j2];console.log(json); /script
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/241759.html