2014-08-31 44 views
1

我在現有的線程中找不到我的問題的答案。我有這個JSON字符串:用C中的fastJson解析JSON#

{ 
    "Count": 4, 
    "Result:000": { 
     "Score": 4.571, 
     "W0DateTime": "2014-08-28 23:00:00", 
     "W0Value": 1.0164, 
     "W0Fibonacci": 0, 
     "Direction": "SHORT", 
     "StartDate": "2014-08-29 16:30:00", 
     "EndDate": "2014-08-28 01:00:00", 
     "BarsCalculated": 80 
    } 
} 

如何獲取Result:000的內容?

我有這樣的代碼:

... 
    public Dictionary<string, object> dictionaryObject; 

    public void jsonInitStructure(string sJsonString) 
    { 
     dictionaryObject = (Dictionary<string , object>) fastJSON.JSON.Parse(sJsonString); 
    } 
... 

Count很簡單:Convert.ToInt32(dictionaryObject ["Count"])但我如何獲取值從Result:000?例如(Score, StartDate, EndDate, ...)

回答

1

您是否嘗試過鑄造它?

var result000 = (Dictionary<string, object>)dictionaryObject["Result:000"]; 
var result000Score = Convert.ToDouble(result000["Score"]); 
+1

完美Rawling!這正是我想要的方式!非常感謝您的幫助。當我讀它時,它看起來簡單得令人難以置信,但我無法自己找出這個演員! – 2014-09-01 10:46:38

0

普萊舍試試...

Array objList = (Array)dictionaryObject["Result:000"] ; 
foreach (object obj in objList) 
{ 
    Dictionary<string, object> dictionary = new Dictionary<string, object>(); 
    dictionary = (Dictionary<string, object>)obj; 

    var var1 = dictionary["Score"].ToString(); 
    var var2 = dictionary["W0DateTime"].ToString(); 

} 
+0

謝謝你的幫助。這不起作用。引發此錯誤:無法將類型爲「System.Collections.Generic.Dictionary'2 [System.String,System.Object]」的對象轉換爲類型「System.Array」。但是Rawling的解決方案非常完美!再Thnx! – 2014-09-01 10:44:13