2012-09-18 128 views
0

我有一套數據(鍵值對),我需要映射到JSON, 注意鍵不固定,鍵的名稱是不固定的。謝謝 例如如何生成動態數據JSON

如何映射

dict<string, list<string>> 
    {"Module",new List<String>(){"Allprice"}}, 
     {"Code",new List<String>(){"PA0000606", "PA0000669"}}, 
    {"ContinuosForwardPeriod", new List<string>() {"0"} , 
    { "TimeStampID", new List<string>{"0"}, 
    {"PriceTypeID": "8"} 

[ 
{ "Module": "Allprice", 
    "Code": "PA0000606", 
    "ContinuosForwardPeriod": "0", 
    "TimeStampID": "0", 
    "PriceTypeID": "8" 
}, 
{ "Module": "Allprice", 
    "Code": "PA0000669", 
    "ContinuosForwardPeriod": "0", 
    "TimeStampID": "0", 
    "PriceTypeID": "8" 
} 
] 
+0

未成年人挑剔:正確的拼寫是 「連續」(注二等U)。 –

回答

1
using System.Web.Script.Serialization.JavaScriptSerializer;  
JavaScriptSerializer oSerializer = new JavaScriptSerializer(); 
string JSON = oSerializer.Serialize(yourDict);