Remove double curly brackets from JObject that have been added during deserialization

后端 未结 2 2004
谎友^
谎友^ 2020-12-18 17:51

I have a JSON string that starts and ends with curly brackets \"{}\".

I then deserialize the object but when this is done I see that I now have double curly brackets

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 18:29

    In my case I want

    "object" : {
            [
                {"a"="b"},
                {"a"="b"},
                {"a"="b"},
                [
                    {"a"="b"},
                    {"a"="b"}
                ]
            ]
        }
    
    To
    
    "object" : {
            [
                {"a"="b"},
                {"a"="b"},
                {"a"="b"},
                {"a"="b"},
                {"a"="b"}
            ]
        }
    

    So Simple I using foreach like this

    alpha =  @"[{'a'='b'},{'a'='b'}]";
    JArray arrayObject = JArray.Parse(alpha);
    foreach (var item in arrayObject)
    {
        obj["object"].Last.AddAfterSelf(item);
    }
    

提交回复
热议问题