I'm having a problem trying to deserialize this json array and trying to use the variables. here is the json array that I'm trying to use
[ {
"Room": [
{
"ID": 347,
"Name": "Beach Villas (68 SQM)",
"Description": "Nestled amidst the vegetation along the pristine white beach, the elegantly designed Beach Villas feature natural wood & stone flooring, open-air bathroom, private outdoor setting with direct access to the beach. ",
"FileImageUrl": "http://url.com?filedataid=160"
}
],
"RoomFacility": [
{
"Facility": "Air conditioning"
},
{
"Facility": "Coffee/tea/espresso making facilities"
},
{
"Facility": "Private Deck"
},
{
"Facility": "Mini Bar"
},
{
"Facility": "Internet Access"
},
{
"Facility": "Ceiling fan"
},
{
"Facility": "Complimentary internet access"
},
{
"Facility": "CD/DVD player with home theater system and satellite TV"
},
{
"Facility": "Outdoor Bathroom and Jacuzzi Bathtub"
},
{
"Facility": "Safety Box"
}
] }]
c# code to retreive parse JSON arry
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri);
httpWebRequest.Method = WebRequestMethods.Http.Get;
httpWebRequest.Accept = "application/json";
var response = (HttpWebResponse)httpWebRequest.GetResponse();
string text;
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
}
StringBuilder sb = new StringBuilder();
dynamic stuff = JsonConvert.DeserializeObject<object>(text);
string roomID = stuff[0]["Room"]["ID"];
///this line gives me error
from this I'm trying to retrive values using the dynamic variable.. I tried something like the last line
ERROR
Accessed JArray values with invalid key value: "ID". Array position index expected. any help would be appreciated?