-1

I get a .json file with such a structure. My question is, how can I effectively read out all the properties and also change them if necessary? I have tried it with objects, but I don't know exactly how I can implement this due to the many nestings.

{  
  "background": {
    "active": true,
    "layer": {
      "img1": {
        "color": "green",
        "active": true
      },
      "img2": {
        "color": "blue",
        "active": true
      }
    }
  },
  "front": {
    "active": true,
    "layer": {
      "img1": {
        "color": "green",
        "active": true
      },
      "img2": {
        "color": "blue",
        "active": true
      },
      "imgX": {
        "color": "blue",
        "active": true
      }
    }
  }
}
Rand Random
  • 7,300
  • 10
  • 40
  • 88
WhatsUuup
  • 1
  • 1

1 Answers1

1

Merry Chirstmas.

Try using Newtonsoft JSON Library

100 Samples

Example usage - Loading JSON

string json = @"{
   'CPU': 'Intel',
   'PSU': '500W',
   'Drives': [
     'DVD read/writer'
     /*(broken)*/,
     '500 gigabyte hard drive',
     '200 gigabyte hard drive'
   ]
}";

JsonTextReader reader = new JsonTextReader(new StringReader(json));
while (reader.Read())
{
    if (reader.Value != null)
    {
        Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
    }
    else
    {
        Console.WriteLine("Token: {0}", reader.TokenType);
    }
}

// Token: StartObject
// Token: PropertyName, Value: CPU
// Token: String, Value: Intel
// Token: PropertyName, Value: PSU
// Token: String, Value: 500W
// Token: PropertyName, Value: Drives
// Token: StartArray
// Token: String, Value: DVD read/writer
// Token: Comment, Value: (broken)
// Token: String, Value: 500 gigabyte hard drive
// Token: String, Value: 200 gigabyte hard drive
// Token: EndArray
// Token: EndObject
Dean Van Greunen
  • 5,060
  • 2
  • 14
  • 28