小编Eri*_*cMA的帖子

C# 使用 Newtonsoft.Json 将 JSON 字符串反序列化为对象

我正在尝试使用 Newtonsoft.json 将 json 字符串转换为对象,但以下转换遇到一些问题。我想知道是否有人可以解释这一点。谢谢。

AddFaceResponse ir = JsonConvert.DeserializeObject<AddFaceResponse>(responseContentStr);
Run Code Online (Sandbox Code Playgroud)

这是 json 字符串 responseContentStr

[{
    "faceId": "1fe48282-a3b0-47d1-8fa8-67c4fac3d984",
    "faceRectangle": {
        "top": 80,
        "left": 50,
        "width": 147,
        "height": 147
    }
}]
Run Code Online (Sandbox Code Playgroud)

这是我的模型对象。

public class AddFaceResponse
    {
        public class Face
        {
            public class FaceRectangle
            {
                public int top, left, width, height;
                public FaceRectangle(int t, int l, int w, int h)
                {
                    top = t;
                    left = l;
                    width = w;
                    height = h;
                }
            }
            public string faceId;
            public FaceRectangle faceRectangle;
            public Face(string id, …
Run Code Online (Sandbox Code Playgroud)

c# serialization json json.net

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

json ×1

json.net ×1

serialization ×1