My JSON looks something like this:
{
"Master" : {
"Major" : "S",
"Minor" : "E",
"IPAddress" : "0.0.0.0",
"Detail":"<root>
<key keyname=\"state\">3</key>
<key keyname=\"oldState\">1</key>
<key keyname=\"currency\"></key>
<key keyname=\"denomination\"></key></root>",
"SourceCreateDate" : "2014-04-03T14:02:57.182+0200"
},
"Messages" : [{
"MessageCode" : "0",
"MessageType" : "8"
}]
}
I'm getting an 'Invalid Characters found' error when validating this. Where are the invalid characters and how can I make this JSON valid?
{
"Master": {
"Major": "S",
"Minor": "E",
"IPAddress": "0.0.0.0",
"Detail": "<root><key keyname=\"state\">3</key><key keyname=\"oldState">1</key><key keyname=\"currency\"></key><key keyname=\"denomination\"></key></root>",
"SourceCreateDate": "2014-04-03T14:02:57.182+0200"
},
"Messages": [
{
"MessageCode": "0",
"MessageType": "8"
}
]
}
JSON validator: http://jsonlint.com/
Edit: Explication: when you open a "
you need to close it on the same line. So you have to put your xml on a single line or to escape it.
JSON only accepts single line Strings.
A work-around would be:
"Detail": [
"<root>",
",<key keyname=\"state\">3</key>",
"<key keyname=\"oldState\">1</key>",
"<key keyname=\"currency\"></key>",
"<key keyname=\"denomination\"></key></root>"
],
You also have the option to replace line breaks into \n
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With