Code
protected void Page_Load(object sender, EventArgs e)
{
string jsonstr = Request.QueryString["people"].ToString();
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string,object> json = (Dictionary<string,object>)serializer.DeserializeObject(jsonstr);
//json["programmers"]返回一個object但這個object是一個object[]怎麼遍歷把他們的值取出來?
}
jsonstr是在客戶端
Code
var people = { "programmers": [{ "firstName": "Brett", "lastName": "McLaughlin",
"email": "brett@newInstance.com"
}, { "firstName": "Jason", "lastName": "Hunter",
"email": "jason@servlets.com"
}, { "firstName": "Elliotte", "lastName": "Harold",
"email": "elharo@macfaq.com"}], "authors": [{ "firstName": "Isaac",
"lastName": "Asimov", "genre": "science fiction"
}, { "firstName": "Tad",
"lastName": "Williams", "genre": "fantasy"
}, { "firstName": "Frank",
"lastName": "Peretti", "genre": "christian fiction"}], "musicians": [
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano"}]
}
var url = "Default.aspx?people=" +people.toJSONString();
異步傳過來的。