Click here to Skip to main content
14,697,191 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got this Json data:

I declare struct like this:

public class Currency
            public string currency_code { get; set; }
            public string currency_name { get; set; }
            public string buy { get; set; }
            public string transfer { get; set; }
            public string sell { get; set; }

I tried with Newtonsoft.Json dll but still cant convert that json array to my struct.

Anybody got a clue or an example code?

Your json can't be directly converted to Currency array as it is in the form of key value pair.

I have found that there is one extra comma "," got added in the last for the json which is creating the problem.

I tried converting the provided json to Dictionary<string, Currency> and I got success after removing the incorrect comma from the json.

try this.

string json = "{" +
                      "\"1\":{\"currency_code\":\"USD\",\"currency_name\":\"USDOLLAR\",\"buy\":\"18990\",\"transfer\":\"18990\",\"sell\":\"19050\"}," +
                      "\"2\":{\"currency_code\":\"EUR\",\"currency_name\":\"EURO\",\"buy\":\"23596.94\",\"transfer\":\"23667.94\",\"sell\":\"23981.34\"}" +

 Dictionary<string, Currency> list =
          new JavaScriptSerializer().Deserialize<Dictionary<string, Currency>>(json);
thank you Prakash Kalakoti :-D

the last ',' is my fault, there r USD, EUR, HKD, AUD, bla bla but i just copy 2 of them and i forgot to remove the last ',' ;P
PSK_ 9-Jun-10 6:07am
If your issue is resolved then you can close the question.
backstr = wr.GetGroup("Sij-kjsgEoG9CtE9Rm8ZiyiwuL3-58K1fZlmXIU5iyYVEFoDJ7d0Idn3-bOooAf1GDIzrJua7Am0yZDXW3bWOUuK_xa6eBELSNhmwLaxhoX3C34g9HvYCf9BTOk9bBukFaLNsoU2djsRfm0M5UHPmw");


456-7890","startTime":"1278614803000","displayStartDateTime":"7/8/10 11:46 AM","displayStartTime":"11:46 AM","relativeStartTime":"5 days


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900