Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# JSON
I got this Json data:
{
"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"},
}
 
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 13:22pm
Rate this: bad
good
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);
  Permalink  
v2
Rate this: bad
good
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
  Permalink  
Comments
Prakash Kalakoti at 9-Jun-10 6:07am
   
If your issue is resolved then you can close the question.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

Solution 4

{"messages":{
 
"a00fbaa04cd9c4aed72943142c197f576018f4e7":{"id":"a00fbaa04cd9c4aed72943142c197f576018f4e7","phoneNumber":"+11234567890","displayNumber":"(123)
 
456-7890","startTime":"1278614803000","displayStartDateTime":"7/8/10 11:46 AM","displayStartTime":"11:46 AM","relativeStartTime":"5 days
 
ago","note":"","isRead":true,"isSpam":false,"isTrash":false,"star":false,"labels":["received","all"],"type":1,"children":""},
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 255
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 14 Jan 2014
Copyright © CodeProject, 1999-2014
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