Bihag
Bihag

Reputation: 1

converting list in json response to comma delimed

Hi I have below json response object converted to string

json object:

{"docInformation":[{"docsWithinTheAlertingRegion":[2134,12521],"toatlNotifiedViaSms":0,"totalAccepted":1}]}

How to convert the docsWithinTheAlertingRegion":[2134,12521] to comma delimited text docsWithinTheAlertingRegion":2134,12521?

The output I want is json object:

{"docInformation":[{"docsWithinTheAlertingRegion":2134,12521,"toatlNotifiedViaSms":0,"totalAccepted":1}]}

Below is snippet of my code

**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);**

Upvotes: 0

Views: 26

Answers (1)

Nozar Safari
Nozar Safari

Reputation: 505

i dont understand what your code do But This Pure JS code do what u need

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)

Upvotes: 1

Related Questions