0

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 complete data.

How can I replace illegal characters of a string to a valid json object?

kryger
  • 12,906
  • 8
  • 44
  • 65
Lay Leangsros
  • 9,156
  • 7
  • 34
  • 39

2 Answers2

0

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.

http://jsonlint.com/

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"
}
Robmeister2015
  • 219
  • 1
  • 3
  • 13
0

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>
Jerry
  • 114
  • 2
  • 13