Append data in a json file in C#

前端 未结 3 2022
庸人自扰
庸人自扰 2020-12-07 02:51

How would i keep appending data? I have this:

{
  \"13232\": [
    \"2012952\"
  ]
}

And i want to add an another object to it, example:

3条回答
  •  悲&欢浪女
    2020-12-07 02:56

    I recommand you use Newtonsoft Json lib, available as a nuget package.

    You can the make a model class to represent on of the json node then you can de-serialize you Json to that model and build an array containing the new element at the end to then re-serialize it to json after.

    Look at this MSDN page about it: https://msdn.microsoft.com/en-us/library/bb412179(v=vs.110).aspx

    Edit: Actual NewtonSoft Documentation

    In steps: 1 Deserialize the collection

    2: And a new class instance with listName.Add(className);

    3: Reserialize the collection

提交回复
热议问题