Peter VARGA
Peter VARGA

Reputation: 5186

Parsing JSON with fastJson in C#

I could not find an answer in the existing threads for my problem. I have this JSON string:

{
    "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
    }
}

How do I get the content of Result:000?

I have this code:

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

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

Count is easy: Convert.ToInt32(dictionaryObject ["Count"]) but how do I get the values from Result:000? For example (Score, StartDate, EndDate, ...)

Upvotes: 1

Views: 2139

Answers (2)

Dewz
Dewz

Reputation: 264

Plese have a try...

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();

 }

Upvotes: 0

Rawling
Rawling

Reputation: 50144

Have you tried casting it?

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

Upvotes: 3

Related Questions