2014-01-17 25 views
0

早些時候,我用來做對象,如:我想要發佈定格式的JSON對象中的Windows Phone

JObject json = new JObject(
        new JProperty("user", user, 
        new JProperty("credit", credit),       
        new JProperty("name", name) 
        ); 

但在這種情況下,我想裏面的一環。當我使JSON對象和其格式我使用JsonConvert.SerializeObject(data, jsSettings),但我發現\/斜槓和我需要的格式不是這種格式。

Json Format : 

{ 
    "user":some value 
    "credit":some value 
    "data":[ 
     { "friend":some value 
      "friend_list:some value" 
     }, 
     {},.. 
    ] 
} 

回答

0

您可以使用DataContractJsonSerializer和json2Csharp解析JSON對象 這裏有個小例子,可以幫助你。

MemoryStream memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)); 
    DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(RootObject)); 
    //here are the parse data 
RootObject itemDataList = dataContractJsonSerializer.ReadObject(memoryStream) as RootObject; 
0

用途:http://james.newtonking.com/json最好的JSON庫,然後嘗試這個例子

產品P1 =新產品 { 名稱= 「產品1」, 價格=99.95米, ExpiryDate =新的日期時間(2000年,12,29,0,0,0,DateTimeKind.Utc), }; 產品P2 =新產品 { 名稱= 「產品2」, 價格=12.50米, ExpiryDate =新日期時間(2009年,7,31,0,0,0,DateTimeKind.Utc) };

List products = new List(); products.Add(p1); products.Add(p2);

string json = JsonConvert.SerializeObject(products,Formatting.Indented);

更多的參考,你可以檢查此鏈接:做這個我得到的JSON作爲{/「FRIEND_LIST」 \/\一些值,那麼一些反斜槓} http://james.newtonking.com/json/help/index.html

+0

無 – Dragon