JSON

Kiegészítő: Newtonsoft.Json

using Newtonsoft.Json.Linq;

 
JSON példa
{
    "eBooks":[
        { 
            "language":"Pascal",
            "edition":3
        },
        {
            "language":"Python",
            "edition":4
        },
        {
            "language":"SQL",
            "edition":2
        }
    ]
}
 
JSON olvasása
JObject eBooksObject = JObject.Parse(JSON);
JArray eBooks = (JArray)eBooksObject.SelectToken("eBooks");
int count = eBooks.Count;
for (int i=0; i<count; i++) {
    string language = (string)eBooks[i].SelectToken("language");
    int edition = (int)eBooks[i].SelectToken("edition");
    Console.WriteLine(language + "/" + edition);
}
 
JSON létrehozása
JObject MP3Object = new JObject();
JArray MP3s = new JArray();
for (int i = 0; i < 3; i++) {
    JObject files = new JObject();
    files.Add("filename", "music" + i + ".mp3");
    files.Add("date", 2000 - i);
    MP3s.Add(files);
}
MP3Object.Add("MP3", JArray.FromObject(MP3s));
Console.WriteLine(MP3Object.ToString());
Mobilos kategóriák: