5,380 questions
Hello,
Welcome to Microsoft Q&A!
- Read the json content from file .
- Deserialize the content into object .
- Add a new property named image in model and assign the value to it .
- Serialize the object into json string .
- Write the string into file .
Model
public class RootObject
{
public string name { get; set; }
public string id { get; set; }
public string image { get; set; } // add this property
}
Original json data
{"name":"cole" , "id" : "123"}
Handling
var file = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "test.json");
if (File.Exists(file))
{
string text = File.ReadAllText(file);
RootObject obj = JsonConvert.DeserializeObject<RootObject>(text);
obj.image = "https://us.v-cdn.net/5019960/uploads/userpics/468/p1NMCBY2PV254.jpeg";
string json = JsonConvert.SerializeObject(obj);
File.WriteAllText(file, text);
}
(Embedding resource does not support writing operation , so we can't use it . )
Best Regards,
Cole Xia
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.