Reputation: 21641
I've an XML object converted into the following JSON object
"{"?xml":{"@version":"1.0","@encoding":"utf-8"},"Response":{"Users":null,"Messages":{"Tell":{"Notify":{"@From":"abc","@Message":"hi system, its abc<br/>"}},"Group":null},"PersistedMessages":{"Tell":null,"Group":null}}}"
How can i get the values inside the xml nodes from this JSON object. For example, how can i get that the version is 1.0 from the @version
attribute?
Thank you.
Upvotes: 0
Views: 405
Reputation: 65254
var json = {
"?xml": {
"@version": "1.0",
"@encoding": "utf-8"
},
"Response": {
"Users": null,
"Messages": {
"Tell": {
"Notify": {
"@From": "abc",
"@Message": "hi system, its abc<br/>"
}
},
"Group": null
},
"PersistedMessages": {
"Tell": null,
"Group": null
}
}
}
alert(json["?xml"]["@version"]);
Upvotes: 1
Reputation: 41812
To get the version, once you have the JSON object (lets call it xobj), use:
xobj['?xml']['@version']
When a javascript object has properties that are cannot be referenced using the '.' operator (because they don't conform to the variable naming rules) like your properties above, you can access the properties using the [''] method.
Upvotes: 2