i’m new to JSON
1. i got json result in html in following format
JSon Result
Alert(result)
{"resort0":"Abaco Beach Resort at Boat Harbour","resort1":"Alexandra Resort","room0":"1 Bedroom Luxury Oceanfront Suite","room1":"2 Bedroom Deluxe Ocean View Suite","room2":"Deluxe Garden View Studio","room3":"Deluxe Ocean View Studio","room4":"Deluxe Oceanfront","room5":"Oceanfront","room6":"Superior Oceanfront"}
alert(result.resort1); // alert "undefined"
alert(result.resort0); // alert "undefined"
2
. how do i get such format with java code JSONObject
is Resorts is key of map ?
{
"Resorts" : [
{ "name" : "Resort1", // First element
"room1" : "rooms1"
"room2" : "rooms2" },
{ "name" : "Resort2", // Second element
"room1" : "rooms1",
"room2" : "rooms2", }
]
}
Be careful. If the json to the variable “result” is in your second code block, you can’t expect to find any data by using “result.resort0” or “result.resort1”. In your example, result contains a submember called “Resorts” which holds an array of submembers.
In other words, to cycle through all values, I would expect javascript like: