Click here to Skip to main content
12,406,333 members (66,222 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# JSON
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?
Posted 8-Jun-10 12:22pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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);
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

thank you Prakash Kalakoti Big Grin | :-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 ',' Poke tongue | ;-P
Prakash Kalakoti 9-Jun-10 6:07am
If your issue is resolved then you can close the question.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

backstr = wr.GetGroup("Sij-kjsgEoG9CtE9Rm8ZiyiwuL3-58K1fZlmXIU5iyYVEFoDJ7d0Idn3-bOooAf1GDIzrJua7Am0yZDXW3bWOUuK_xa6eBELSNhmwLaxhoX3C34g9HvYCf9BTOk9bBukFaLNsoU2djsRfm0M5UHPmw");
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160726.1 | Last Updated 14 Jan 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100