我有一個接收JSON字符串作爲參數的Web服務。當我的web方法的參數是泛型類型的「對象」時,我只能成功發送這個消息。如何序列化這個JSON對象?
我可以將此通用對象序列化爲字符串或自定義對象嗎?我是否需要修改此方法的參數類型?任何幫助都是極好的。
這裏是Web方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string StoreDataOut(object json)
{
//serialization magic
}
這是正在傳遞給此Web方法測試JSON:
{
"uid":"1234abcd",
"application":"Application Name",
"eventName":null,
"clienttoken":"Test Client",
"version":"1.0.0",
"datetime":"1/1/2011 12:00 AM",
"data":[
{
"id":"alpha_123",
"question":"ronunciations in pre-classical times or in non-Attic dialects. For det",
"answer":"nunciations "
},
{
"id":"beta_456",
"question":"official documents such as laws an",
"answer":"or modif"
},
{
"id":"gamma_789",
"question":" maintained or modified slightly to fit Greek phonology; thus, ?",
"answer":"iation of Attic"
},
{
"id":"delta_098",
"question":"econstructed pronunciation of Attic in the late 5th an",
"answer":"unciation of "
},
{
"id":"epsilon_076",
"question":"erent stylistic variants, with the descending tail either going straight down o",
"answer":"Whole bunch"
},
{
"id":"zeta_054",
"question":"rough breathing when it begins a word. Another diacritic use",
"answer":"other dia"
}
]
}
它會工作嗎?!酷..我試試。 – Nick
這讓我非常接近..但名單「數據」沒有得到填充 – Nick
沒關係.. :)謝謝男人..我不知道,asp.net只會映射這樣的屬性。 – Nick