I'm try converting from xml string to json string as below:
I have xml string structure like this.
- <items>
- <item>
- <id>1</id>
- <name>Name 1</name>
- </item>
- <item>
- <id>2</id>
- <name>Name 2</name>
- </item>
- </items>
When I try convert to json. I got result as array of item. It's good result.
- {
- "items": {
- "item": [
- {
- "id": "1",
- "name": "Name 1"
- },
- {
- "id": "2",
- "name": "Name 2"
- }
- ]
- }
- }
But when my xml have only one item.
- <items>
- <item>
- <id>1</id>
- <name>Name 1</name>
- </item>
- </items>
I got result as object of item.
- {
- "items": {
- "item": {
- "id": "1",
- "name": "Name 1"
- }
- }
- }
But the exactly result I want to get like this.
- {
- "items": {
- "item": [
- {
- "id": "1",
- "name": "Name 1"
- }
- ]
- }
- }