0

I am using Newtonsoft and Newtonsoft.Json. I have the below json:

string strJson_StorageInfo = "[{10:\"test\"}, {20:\"test1\"}]";

List<Dictionary<int, string>> jobj = (List<Dictionary<int, string>>) JsonConvert.DeserializeObject(strJson_StorageInfo, typeof(List<Dictionary<int, string>>));
foreach (Dictionary<int, string> dicStorageInfo in jobj) {
   foreach (KeyValuePair<int, string> StorageItem in dicStorageInfo) {
      Response.Write("key : " + StorageItem.Key + " , value : " + StorageItem.Value + "</br>"); 
   }
}

I need to Deserialize this. Can anyone suggest me good method. Thanks in advance

3
  • I only see a string here, no usage of Newtonsoft. Are you serializing the JSON above? Commented May 30, 2014 at 10:27
  • List<Dictionary<int, string>> jobj = (List<Dictionary<int, string>>) JsonConvert.DeserializeObject(strJson_StorageInfo, typeof(List<Dictionary<int, string>>)); foreach (Dictionary<int, string> dicStorageInfo in jobj) { foreach (KeyValuePair<int, string> StorageItem in dicStorageInfo) { Response.Write("key : " + StorageItem.Key + " , value : " + StorageItem.Value + "</br>"); } } i feel unnecessary enumuration on list objects and then dictionary object. Commented May 30, 2014 at 10:36
  • stackoverflow.com/questions/14934360/… Did you try this? Commented May 30, 2014 at 10:56

3 Answers 3

0

you can use below mentioned code

string strJson_StorageInfo = "[{10:\"test\"}, {20:\"test1\"}]";
var abc = JsonConvert.DeserializeObject <List<Dictionary<int, string>>>(strJson_StorageInfo);

after you can find the keys and Values from it

  var K = abc.Select(p => p.Keys);
  var V = abc.Select(p => p.Values);
Sign up to request clarification or add additional context in comments.

1 Comment

I am using asp.net 2.0
0

ok. I compromised with Json Format String. I have changed the json string. Found similar thread in How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?. Thanks.

Comments

0

This worked for me.. I am not sure if it works in asp.net 2.0

string strJson_StorageInfo = "[{10:\"test\"}, {20:\"test1\"}]";
List<Dictionary<int, string>> values = JsonConvert.DeserializeObject<List<Dictionary<int, string>>>(strJson_StorageInfo);
foreach (var items in values)
{
    foreach (var item in items)
    {
        Label1.Text += "Key: " + item.Key.ToString() + " Value: " + item.Value.ToString() + "<br/>";
    }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.