Convert From Invalid To Valid Json
I have json which contains illegal characters {'message':'A'B', 'fromWhom':'53'} I want plaint text which is sent from the sever spring to client, so that client can get the com
Solution 1:
This is valid:
{"message":"A B","fromWhom":"53"}
Is there a reason you have a floating quote mark in there?
Also, this resource is useful for validating JSON.
I hope this is the answer to your question.
EDIT:
If you must use the double quote, then you can escape it as shown below and it will be valid.
{
"message": "A\"B",
"fromWhom": "53"
}
Solution 2:
I think you need to escape the quote.
{
"message": "A\"B",
"fromWhom": "53"
}
As for changing the value. I think you need to JSON.parse.
Example:
<script>var text = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';
obj =JSON.parse(text);
obj.employees[1].lastName ="Timmy"//Value change here
document.getElementById("demo").innerHTML =
obj.employees[1].firstName +" "+ obj.employees[1].lastName;
</script>
Post a Comment for "Convert From Invalid To Valid Json"