這裏我有json字符串,我想從這個json字符串獲得一個關鍵字和值。所以我已經使用了JavaScript序列化程序。 下面是我在C#.Net中使用的代碼。如何將json對象轉換成字符串
string strProfile = fbApi.GetForStr("/statefarm/feed/");
var jss = new JavaScriptSerializer();
var dictionary = (IDictionary<string, object>)jss.DeserializeObject(strProfile);
object keyvalue = (object)dictionary["paging"];
string data = keyvalue.ToString();
當我這樣做時,我無法從jsonstring中獲取keyvale對。如果我寫
string keyvalue = (string)dictionary["paging"];
,而不是
object keyvalue = (object)dictionary["paging"];
string data = keyvalue.ToString();
越來越名爲類型的
對象System.Object的'輸入 'system.string' 例外
該怎麼做以及如何寫入。
那麼......它的類型是'System.Object' - 你期望什麼?演員陣容是否適合? ... nope ...'.ToString()'或任何其他轉換將成爲你的朋友! –
你可以加入json嗎? –
你試過字典[「分頁」]。toString()或類似的東西嗎? – dutt