正解:A
When converting XML to JSON, the structure should maintain the hierarchical organization and data representation. The provided XML structure:
<books>
<science>
<biology>10.00</biology>
<geology>9.00</geology>
<chemistry>8.00</chemistry>
</science>
<math>
<calculus>20.00</calculus>
<algebra>12.00</algebra>
</math>
</books>
translates to the following JSON structure:
{
"books": {
"science": {
"biology": "10.00",
"geology": "9.00",
"chemistry": "8.00"
},
"math": {
"calculus": "20.00",
"algebra": "12.00"
}
}
}
* Root Element: The root element <books> translates to a key "books".
* Nested Elements: The <science> and <math> elements become nested objects under "books".
* Leaf Elements: The individual subjects and their prices (e.g., <biology>10.00</biology>) become key-value pairs within their respective parent objects.
Option A:
json
Copy code
{
"books": {
"science": {
"biology": "10.00",
"geology": "9.00",
"chemistry": "8.00"
},
"math": {
"calculus": "20.00",
"algebra": "12.00"
}
}
}
This option accurately represents the hierarchical structure of the XML data, making it the correct equivalent.
Option B, C, and D:
* These options incorrectly use array notation for the nested objects, which is not consistent with the original XML structure. The XML structure indicates that "science" and "math" are single objects with multiple key-value pairs, not arrays.
References:
* Converting Between XML and JSON
* JSON and XML Comparison