Json.NET (Newtonsoft.Json) - Two 'properties' with same name?

后端 未结 2 1049
广开言路
广开言路 2020-12-02 01:05

I\'m coding in C# for the .NET Framework 3.5.

I am trying to parse some Json to a JObject.

The Json is as follows:

{
    \"TBox\": {
                 


        
2条回答
  •  悲&欢浪女
    2020-12-02 01:41

    If I'm not mistaken, the correct answer to this is that your input is not actually JSON. So no, getting a JSON parser to parse it probably isn't going to work.

    Maybe you don't have any control over the source of the input, so I'd use a Regex or something to pre-filter the string. Turn it into something like:

    {"TBoxes":
        [
            {
                "Name": "SmallBox",
                "Length": 1,
                "Width": 1,
                "Height": 2 
            },
            {
                "Name": "MedBox",
                "Length": 5,
                "Width": 10,
                "Height": 10 
            },
            {
                "Name": "LargeBox",
                "Length": 20,
                "Width": 20,
                "Height": 10 
            }
        ]
    }
    

    And treat it like the array that it is.

提交回复
热议问题