I just can't get key and value for embedded object in json.
I want to get these keys and values like { user: 'admin', msg: 'exit' }.
With this code I get item.Key (that is id in that json) and item.Value (System.Collections.Generic.Dictionary`2[System.String,System.Object])
But I just don't know what to do with this object. How to get data from it?
I get json from server -
{
"365": {
"user": "admin",
"msg": "exit"
},
"366": {
"user": "user",
"msg": "enter"
},
"370": {
"user": "user",
"msg": "exit"
},
"372": {
"user": "user",
"msg": "exit"
},
"373": {
"user": "admin",
"msg": "exit"
}
}
Thank you for any answer.
P.S. I don't want to use any external libs.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Web.Script.Serialization;
namespace JSONTestconsole
{
class Program
{
static void Main(string[] args)
{
WebClient wc = new WebClient();
wc.Proxy = null;
string data = wc.DownloadString("http://temp.net");
JavaScriptSerializer ser = new JavaScriptSerializer();
var obj = ser.DeserializeObject(data) as ICollection;
foreach (KeyValuePair<string, object> item in obj)
{
var id = item.Key;
Console.WriteLine(id);
Console.WriteLine(item.Value);
}
Console.ReadLine();
}
}
}