Home > Enterprise >  System.Text.Json.deserialize Json String
System.Text.Json.deserialize Json String

Time:10-18

I have a question about System.Text.Json.deserialize. I have got the Json value like this

    {
        "id" :"1",
        "ShopName" :"Paint Shop",
        "Books" : [1,2]
    }

It can easy convert to simple object as

    public class bookstore {
        public int id {get;set}
        public string ShopName {get;set}
        public IEnumerable<int> Books {get;set}
    }

But I have a function which convert books array int into list of object like this

    {
        "id" :"1",
        "ShopName" :"Paint Shop",
        "Books" : [
            {
                "bookId":1,
                "bookName":"Peter Pan",
                "location":"A01"
            },
            {
                "bookId":2,
                "bookName":"Cooking Book",
                "location":"A02"
            }
        ]
    }

Right now, I want to modify the value of Books[1].location value, by using jsonnode.parse(string) to convert the object. Can I know how to do it ?

Thank you

CodePudding user response:

Don't know why you want to use the JsonNode.Parse().

If you just want to modify the location's value, maybe you can use the JsonSerializer with BookStore and Book class to help you.

  • Related