0
votes

I am new in android , I am having queries in json:-

How can I break the line in json if i having multiple lines? Like This:
{"contacts":
[
{ "id": "c200",
"name": "Ravi Tamada",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender": "male",
"About": "Sentence1.Sentence2.Sentence3",
"phone": { "mobile": "+91 0000000000",
"home": "00 000000",
"office": "00 000000" }
}
]
}

1
Can we see the json file you are working with?Ahmed Abidi
{ "id" : "7", "illustrationurl" : "../../Img/Illustrations/pursesnatcher25.jpg", "para1" : "sentence1.sentence2.sentence3.", "title" : "“Purse Snatcher”" }Anshul Khare

1 Answers

0
votes

If you just desire it to be a line break, use the code for the String you are using in the application. Json are "data-only" for transfer, so they should not have any formatting.

IF the data is formatted, is directly as it should be used:

Example:

{"MyVarName":"Sentence1\nSentence2\nSentence3"}

Then on lets say a javascript (using ajax for simplicity)

$.ajax({
        dataType: "json",
        url: url,
        success: function(output){
            alert(output["MyVarName"]);
        }
    });

Edit:

if you run the example, you will see the correct result.

The following will provide the correct results: "About": "Sentence1.\nSentence2.\nSentence3", if you are using another system, you need to writte the correct line break. meaning that in HTML the linebreak is </br>, in javascript it is \nu.s.f. check the line break needed then append in the position desired.