嗨,我有以下JSON响应对象转换为字符串
json对象:
{"docInformation":[{"docsWithinTheAlertingRegion":[2134,12521],"toatlNotifiedViaSms":0,"totalAccepted":1}]}
如何将docsWithinTheAlertingRegion":[2134,12521]
转换为逗号界限文本docsWithinTheAlertingRegion":2134,12521
?
我想要的输出是JSON对象:
{"docInformation":[{"docsWithinTheAlertingRegion":2134,12521,"toatlNotifiedViaSms":0,"totalAccepted":1}]}
下面是我的代码的片段
**BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
System.out.println("line number:"+ inputLine);
response.append(inputLine);
}
in.close();
JSONObject jsonObj = new JSONObject(response.toString());
String str = XML.toString(jsonObj);**
我不明白您的代码在做什么但是,此纯JS代码可以做您需要的
data={"docInformation":[{"docsWithinTheAlertingRegion":[2134,12521],"toatlNotifiedViaSms":0,"totalAccepted":1}]}
data.docInformation.forEach(function (info , index){
var tmresult =""
info.docsWithinTheAlertingRegion.forEach(function (x){
tmresult += "," + x.toString()
})
data.docInformation[index].docsWithinTheAlertingRegion =tmresult.substring(1)
})
print(data)