欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全

程序员文章站 2023-02-21 09:28:47
Newtonsoft.Json Newtonsoft.Json 是.Net平台操作Json的工具,他的介绍就不多说了,笔者最近在弄接口,需要操作Json。 以某个云计算平台的Token为例,边操作边讲解。 Json 转为 Model 将 Model 转为 Json 将 LINQ 转为 JSON Li ... the default json name table implementation. instructs the jsonserializer how to serialize the collection. instructs the jsonserializer to use the specified constructor when deserializing that object. instructs the jsonserializer how to serialize the object. 提供用于在.net 和 json之间互相转等操作的方法 converts an object to and from json. converts an object to and from json. instructs the jsonserializer to use the specified jsonconverter when serializing the member or class. represents a collection of jsonconverter. instructs the jsonserializer how to serialize the collection. json序列化或反序列化过程中发生错误时引发的异常类型 instructs the jsonserializer to deserialize properties with no matching class member into the specified collection and write values during serialization. instructs the jsonserializer not to serialize the public field or public read/write property value. base class for a table of atomized string objects. instructs the jsonserializer how to serialize the object. instructs the jsonserializer to always serialize the member with the specified name. represents a reader that provides fast, non-cached, forward-only access to serialized json data. the exception thrown when an error occurs while reading json text. instructs the jsonserializer to always serialize the member, and to require that the member has a value. the exception thrown when an error occurs during json serialization or deserialization. serializes and deserializes objects into and from the json format. the jsonserializer enables you to control how objects are encoded into json. specifies the settings on a jsonserializer object. represents a reader that provides fast, non-cached, forward-only access to json text data. represents a writer that provides a fast, non-cached, forward-only way of generating json data. represents a reader that provides jsonschema validation.  cautionjson schema validation has been moved to its own package. see for more details. represents a writer that provides a fast, non-cached, forward-only way of generating json data. the exception thrown when an error occurs while writing json text. provides an interface for using pooled arrays. provides an interface to enable a class to return line and position information. specifies how constructors are used when initializing objects during deserialization by the jsonserializer. specifies how dates are formatted when writing json text. specifies how date formatted strings, e.g. "\/date(1198908717056)\/" and "2012-03-21t05:40z", are parsed when reading json text. specifies how to treat the time value when converting between string and datetime. specifies default value handling options for the jsonserializer. specifies float format handling options when writing special floating point numbers, e.g. nan,positiveinfinity and negativeinfinity with jsonwriter. specifies how floating point numbers, e.g. 1.0 and 9.9, are parsed when reading json text. specifies formatting options for the jsontextwriter. specifies the state of the reader. specifies the type of json token. specifies the member serialization options for the jsonserializer. specifies metadata property handling options for the jsonserializer. specifies missing member handling options for the jsonserializer. specifies null value handling options for the jsonserializer. specifies how object creation is handled by the jsonserializer. specifies reference handling options for the jsonserializer. note that references cannot be preserved when a value is set via a non-default constructor such as types that implement iserializable. specifies reference loop handling options for the jsonserializer. indicating whether a property is required. specifies how strings are escaped when writing json text. indicates the method that will be used during deserialization for locating and loading assemblies. specifies type name handling options for the jsonserializer. specifies the state of the jsonwriter....

 newtonsoft.json

newtonsoft.json 是.net平台操作json的工具,他的介绍就不多说了,笔者最近在弄接口,需要操作json。

以某个云计算平台的token为例,边操作边讲解。

json 转为 model

将 model 转为 json

将 linq 转为 json

linq 操作

另外附上 百度ai 文字识别 json 及其模型类

 

 newtonsoft.json 将字符串转为对象,是根据类型对象名称进行的,大小写不分,但是名称要一致要,哪怕你的json只有一个

{

"a":1

}

你的对象

public class test

    {
        public int aa{get;set;}
    }

也是不能对应的。

有复杂层次的 json,可以使用 “类中类” 来映射,要注意 list<t>/array/arraylist的类型的使用。


 json 转为 model

 

新建一个 json 文件,名字随意,例如 json1.json

把以下内容粘贴进去

{
  "refresh_token": "25.ea2f85ebd48df85fe5400000.18640.282335-15533349",
  "expires_in": 2592010,
  "session_key": "9mzdwr3n8ncmedgx8zjhkhlw8khb5cdztpevpbpwqgbg==",
  "access_token": "24.ac0ca9fakhlkyhl552017858.282335-15533349",
  "scope": "audio_voice_assistant_get audio_tts_post public vis-ocr_ocr nlp_simnet nlp_wclassify_watermark brain_ocr_scope vis-classify_car brain_gif_antiporn brain_ocr_general brain_ocr_general_basic brain_ocr_generer vis-classify_animal brain_politician brain_unit_utterance brain_imgquality_general brain_nlp_simnet brain_nlp_depparser vis-classify_plant brain_solution brain_ocr_plate_number brain_nlp_wordembedding brain_nlp_dnnlm_cn_legacy brain_nlp_simnet_legacy brain_nlp_commain_animal_classify brain_plant_classify brain_solution_iocr brain_realtime_product brain_nlp_lexer_custom brain_kgbody_analysis brain_body_attr brain_ocr_vat_invoice brain_advanced_general_classify brain_numbers brain_body_number vis-faceverify_face_auth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi",
  "session_secret": "2ca66d464545c77a4767f709873be4"
}

 

定义一个模型,文件名为 accesstokenmodel.cs

    public class accesstokenmodel
    {
        public string refresh_token { get; set; }
        public string expires_in { get; set; }//: access token的有效期(秒为单位,一般为1个月)
        public string scope { get; set; }
        public string session_key { get; set; }
        public string access_token { get; set; }//: 要获取的access token
        public string session_secret { get; set; }
    }

打开 program.cs 文件

            public static void main(string[] args)
            {
                filestream fs = new filestream(@"请修改成你的文件路径\json1.json", filemode.open);
                streamreader filestream = new streamreader(fs);
                string str = "";
                string line;
                while ((line = filestream.readline()) != null)
                {
                    str += line;
                }
          //上面的代码没有意义,只是将json文件的内容加载到字符串中
           jobject jobject = new jobject();        //新建 操作对象 accesstokenmodel a = jsonconvert.deserializeobject<accesstokenmodel>(str); console.writeline(a.access_token);    //随意输出一个属性 console.readkey(); }

 重点方法 

jsonconvert.deserializeobject<要转化的模型类>("字符串对象");

之后可以很方便的把json文件的内容存放到数据库中。

集合

把json文件改成以下的样子

[{
  "refresh_token": "25.ea2f85ebd48df85fe5400000.18640.282335-15533349",
  "expires_in": 2592010,
  "session_key": "9mzdwr3n8ncmedgx8zjhkhlw8khb5cdztpevpbpwqgbg==",
  "access_token": "24.ac0ca9fakhlkyhl552017858.282335-15533349",
  "scope": "audio_voice_assistant_get audio_tts_post public vis-ocr_ocr nlp_simnet nlp_wclassify_watermark brain_ocr_scope vis-classify_car brain_gif_antiporn brain_ocr_general brain_ocr_general_basic brain_ocr_generer vis-classify_animal brain_politician brain_unit_utterance brain_imgquality_general brain_nlp_simnet brain_nlp_depparser vis-classify_plant brain_solution brain_ocr_plate_number brain_nlp_wordembedding brain_nlp_dnnlm_cn_legacy brain_nlp_simnet_legacy brain_nlp_commain_animal_classify brain_plant_classify brain_solution_iocr brain_realtime_product brain_nlp_lexer_custom brain_kgbody_analysis brain_body_attr brain_ocr_vat_invoice brain_advanced_general_classify brain_numbers brain_body_number vis-faceverify_face_auth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi",
  "session_secret": "2ca66d464545c77a4767f709873be4"
},
{
  "refresh_token": "25.ea2f85ebd48df85fe5400000.18640.282335-15533349",
  "expires_in": 2592010,
  "session_key": "9mzdwr3n8ncmedgx8zjhkhlw8khb5cdztpevpbpwqgbg==",
  "access_token": "24.ac0ca9fakhlkyhl552017858.282335-15533349",
  "scope": "audio_voice_assistant_get audio_tts_post public vis-ocr_ocr nlp_simnet nlp_wclassify_watermark brain_ocr_scope vis-classify_car brain_gif_antiporn brain_ocr_general brain_ocr_general_basic brain_ocr_generer vis-classify_animal brain_politician brain_unit_utterance brain_imgquality_general brain_nlp_simnet brain_nlp_depparser vis-classify_plant brain_solution brain_ocr_plate_number brain_nlp_wordembedding brain_nlp_dnnlm_cn_legacy brain_nlp_simnet_legacy brain_nlp_commain_animal_classify brain_plant_classify brain_solution_iocr brain_realtime_product brain_nlp_lexer_custom brain_kgbody_analysis brain_body_attr brain_ocr_vat_invoice brain_advanced_general_classify brain_numbers brain_body_number vis-faceverify_face_auth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi",
  "session_secret": "2ca66d464545c77a4767f709873be4"
}
]

 

            public static void main(string[] args)
            {
                filestream fs = new filestream(@"请修改成你的文件路径\json1.json", filemode.open);
                streamreader filestream = new streamreader(fs);
                string str = "";
                string line;
                while ((line = filestream.readline()) != null)
                {
                    str += line;
                }
                //上面的代码没有意义,只是将json文件的内容加载到字符串中

                jobject jobject = new jobject();        //新建 操作对象
                list<accesstokenmodel> a = jsonconvert.deserializeobject<list<accesstokenmodel>>(str);
                foreach (var i in a)
                {
                    console.writeline(i.access_token);
                }

                console.readkey();
            }

 


将model转为json

能够将模型对象转为 json。

继续使用上面的 accesstokenmodel.cs 文件,

            public static void main(string[] args)
            {
                accesstokenmodel accesstokenmodel = new accesstokenmodel();
                accesstokenmodel.access_token = "test1";
                accesstokenmodel.expires_in = "test2";
                accesstokenmodel.refresh_token = "test3";
                accesstokenmodel.scope = "test4";
                accesstokenmodel.session_key = "test5";
                accesstokenmodel.session_secret = "test6";

                jobject jobject = new jobject();
                string str = jsonconvert.serializeobject(accesstokenmodel);    //转为字符串

                console.writeline(str);
                console.readkey();
            }

重点方法 

jsonconvert.serializeobject(a模型对象);

运行后可以看到控制台输出的是json字符串了,你可以继续把他放到json文件中,这里不再赘述。


将 linq 转为 json

下面这个是从官网直接copy的例子,jarray 是其框架提供的一种类型。

在控制台运行后会发现输出的字符是已经格式化的。

            public static void main(string[] args)
            {
                jarray array = new jarray();
                array.add("manual text");
                array.add(new datetime(2000, 5, 23));

                jobject o = new jobject();
                o["myarray"] = array;

                string json = o.tostring();
                // {
                //   "myarray": [
                //     "manual text",
                //     "2000-05-23t00:00:00"
                //   ]
                // }

                console.writeline(json);
                console.readkey();

 


linq 操作

框架提供了对 jobject 对象的linq操作支持

using newtonsoft.json.linq;

之后你可以像操作数组、集合或者context一样方便。

 


命名空间、类型、方法大全

Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全

本来想翻译一下的,英语太差,算了。在常用的类型前面加粗吧

 

classes
  class description
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 defaultjsonnametable
the default json name table implementation.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonarrayattribute
instructs the jsonserializer how to serialize the collection.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonconstructorattribute
instructs the jsonserializer to use the specified constructor when deserializing that object.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsoncontainerattribute
instructs the jsonserializer how to serialize the object.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonconvert
提供用于在.net 和 json之间互相转等操作的方法
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonconverter
converts an object to and from json.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonconverter<t>
converts an object to and from json.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonconverterattribute
instructs the jsonserializer to use the specified jsonconverter when serializing the member or class.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonconvertercollection
represents a collection of jsonconverter.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsondictionaryattribute
instructs the jsonserializer how to serialize the collection.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonexception
json序列化或反序列化过程中发生错误时引发的异常类型
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonextensiondataattribute
instructs the jsonserializer to deserialize properties with no matching class member into the specified collection and write values during serialization.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonignoreattribute
instructs the jsonserializer not to serialize the public field or public read/write property value.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonnametable
base class for a table of atomized string objects.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonobjectattribute
instructs the jsonserializer how to serialize the object.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonpropertyattribute
instructs the jsonserializer to always serialize the member with the specified name.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonreader
represents a reader that provides fast, non-cached, forward-only access to serialized json data.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonreaderexception
the exception thrown when an error occurs while reading json text.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonrequiredattribute
instructs the jsonserializer to always serialize the member, and to require that the member has a value.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonserializationexception
the exception thrown when an error occurs during json serialization or deserialization.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonserializer
serializes and deserializes objects into and from the json format. the jsonserializer enables you to control how objects are encoded into json.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonserializersettings
specifies the settings on a jsonserializer object.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsontextreader
represents a reader that provides fast, non-cached, forward-only access to json text data.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsontextwriter
represents a writer that provides a fast, non-cached, forward-only way of generating json data.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonvalidatingreader obsolete.

represents a reader that provides jsonschema validation.

Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 caution
json schema validation has been moved to its own package. see for more details.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonwriter
represents a writer that provides a fast, non-cached, forward-only way of generating json data.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonwriterexception
the exception thrown when an error occurs while writing json text.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全interfaces
  interface description
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 iarraypool<t>
provides an interface for using pooled arrays.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 ijsonlineinfo
provides an interface to enable a class to return line and position information.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全enumerations
  enumeration description
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 constructorhandling
specifies how constructors are used when initializing objects during deserialization by the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 dateformathandling
specifies how dates are formatted when writing json text.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 dateparsehandling
specifies how date formatted strings, e.g. "\/date(1198908717056)\/" and "2012-03-21t05:40z", are parsed when reading json text.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 datetimezonehandling
specifies how to treat the time value when converting between string and datetime.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 defaultvaluehandling
specifies default value handling options for the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 floatformathandling
specifies float format handling options when writing special floating point numbers, e.g. nan,positiveinfinity and negativeinfinity with jsonwriter.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 floatparsehandling
specifies how floating point numbers, e.g. 1.0 and 9.9, are parsed when reading json text.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 formatting
specifies formatting options for the jsontextwriter.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsonreader.state
specifies the state of the reader.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 jsontoken
specifies the type of json token.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 memberserialization
specifies the member serialization options for the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 metadatapropertyhandling
specifies metadata property handling options for the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 missingmemberhandling
specifies missing member handling options for the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 nullvaluehandling
specifies null value handling options for the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 objectcreationhandling
specifies how object creation is handled by the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 preservereferenceshandling
specifies reference handling options for the jsonserializer. note that references cannot be preserved when a value is set via a non-default constructor such as types that implement iserializable.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 referenceloophandling
specifies reference loop handling options for the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 required
indicating whether a property is required.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 stringescapehandling
specifies how strings are escaped when writing json text.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 typenameassemblyformathandling
indicates the method that will be used during deserialization for locating and loading assemblies.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 typenamehandling
specifies type name handling options for the jsonserializer.
Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 writestate
specifies the state of the jsonwriter.
 

另外附上 百度ai 文字识别 json 及其模型类

 图片

Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全

百度ai 识别文字,返回json结果, 名字随意.格式建议为 json,如果使用记事本保存,注意编码格式是 utf-8,因为c# string默认为utf8,不然会乱码。

{
  "log_id": 3413661945235258919,
  "direction": 0,
  "words_result_num": 2,
  "words_result": [
    {
      "vertexes_location": [
        {
          "y": 81,
          "x": 51
        },
        {
          "y": 81,
          "x": 151
        },
        {
          "y": 103,
          "x": 151
        },
        {
          "y": 103,
          "x": 51
        }
      ],
      "probability": {
        "variance": 0.0,
        "average": 0.999861,
        "min": 0.999627
      },
      "chars": [
        {
          "char": "今",
          "location": {
            "width": 17,
            "top": 83,
            "left": 60,
            "height": 20
          }
        },
        {
          "char": "天",
          "location": {
            "width": 17,
            "top": 83,
            "left": 78,
            "height": 20
          }
        },
        {
          "char": "除",
          "location": {
            "width": 12,
            "top": 83,
            "left": 103,
            "height": 20
          }
        },
        {
          "char": "了",
          "location": {
            "width": 16,
            "top": 83,
            "left": 116,
            "height": 20
          }
        },
        {
          "char": "皮",
          "location": {
            "width": 13,
            "top": 83,
            "left": 140,
            "height": 20
          }
        }
      ],
      "min_finegrained_vertexes_location": [
        {
          "y": 81,
          "x": 51
        },
        {
          "y": 81,
          "x": 151
        },
        {
          "y": 103,
          "x": 151
        },
        {
          "y": 103,
          "x": 51
        }
      ],
      "finegrained_vertexes_location": [
        {
          "y": 81,
          "x": 51
        },
        {
          "y": 81,
          "x": 71
        },
        {
          "y": 81,
          "x": 90
        },
        {
          "y": 81,
          "x": 110
        },
        {
          "y": 81,
          "x": 129
        },
        {
          "y": 81,
          "x": 149
        },
        {
          "y": 81,
          "x": 151
        },
        {
          "y": 91,
          "x": 151
        },
        {
          "y": 100,
          "x": 151
        },
        {
          "y": 103,
          "x": 151
        },
        {
          "y": 103,
          "x": 132
        },
        {
          "y": 103,
          "x": 112
        },
        {
          "y": 103,
          "x": 93
        },
        {
          "y": 103,
          "x": 73
        },
        {
          "y": 103,
          "x": 54
        },
        {
          "y": 103,
          "x": 51
        },
        {
          "y": 93,
          "x": 51
        },
        {
          "y": 84,
          "x": 51
        }
      ],
      "location": {
        "width": 102,
        "top": 81,
        "left": 51,
        "height": 24
      },
      "words": "今天除了皮"
    },
    {
      "vertexes_location": [
        {
          "y": 109,
          "x": 52
        },
        {
          "y": 109,
          "x": 152
        },
        {
          "y": 130,
          "x": 152
        },
        {
          "y": 130,
          "x": 52
        }
      ],
      "probability": {
        "variance": 8e-05,
        "average": 0.9907,
        "min": 0.973259
      },
      "chars": [
        {
          "char": "又",
          "location": {
            "width": 16,
            "top": 111,
            "left": 61,
            "height": 20
          }
        },
        {
          "char": "啥",
          "location": {
            "width": 12,
            "top": 111,
            "left": 85,
            "height": 20
          }
        },
        {
          "char": "也",
          "location": {
            "width": 16,
            "top": 111,
            "left": 98,
            "height": 20
          }
        },
        {
          "char": "没",
          "location": {
            "width": 15,
            "top": 111,
            "left": 123,
            "height": 20
          }
        },
        {
          "char": "干",
          "location": {
            "width": 13,
            "top": 111,
            "left": 141,
            "height": 20
          }
        }
      ],
      "min_finegrained_vertexes_location": [
        {
          "y": 109,
          "x": 52
        },
        {
          "y": 109,
          "x": 152
        },
        {
          "y": 130,
          "x": 152
        },
        {
          "y": 130,
          "x": 52
        }
      ],
      "finegrained_vertexes_location": [
        {
          "y": 109,
          "x": 52
        },
        {
          "y": 109,
          "x": 71
        },
        {
          "y": 109,
          "x": 91
        },
        {
          "y": 109,
          "x": 110
        },
        {
          "y": 109,
          "x": 129
        },
        {
          "y": 109,
          "x": 149
        },
        {
          "y": 109,
          "x": 152
        },
        {
          "y": 119,
          "x": 152
        },
        {
          "y": 129,
          "x": 152
        },
        {
          "y": 130,
          "x": 152
        },
        {
          "y": 130,
          "x": 133
        },
        {
          "y": 130,
          "x": 113
        },
        {
          "y": 130,
          "x": 94
        },
        {
          "y": 130,
          "x": 74
        },
        {
          "y": 130,
          "x": 55
        },
        {
          "y": 130,
          "x": 52
        },
        {
          "y": 121,
          "x": 52
        },
        {
          "y": 111,
          "x": 52
        }
      ],
      "location": {
        "width": 102,
        "top": 109,
        "left": 52,
        "height": 22
      },
      "words": "又啥也没干"
    }
  ],
  "language": -1
}

对应的模型 ,将 cs 文件,名字  generalmodel.cs

    /// <summary>
    /// 通用文字识别(含位置版)返回结果
    /// </summary>
    public class generalmodel
    {
        /// <summary>
        /// 必选
        /// 唯一的log id,用于问题定位
        /// </summary>
        public long log_id { get; set; }
        /// <summary>
        /// 图像方向,当detect_direction=true时存在。
        /// 非必选
        ///- -1:未定义,
        ///- 0:正向,
        ///- 1: 逆时针90度,
        ///- 2:逆时针180度,
        ///- 3:逆时针270度
        /// </summary>
        public int direction { get; set; }

        /// <summary>
        /// 必选
        /// 识别结果数,表示words_result的元素个数
        /// </summary>
        public int words_result_num { get; set; }

        /// <summary>
        /// 检测语言 默认值会返回 -1
        /// </summary>
        public string language { get; set; }
        /// <summary>
        /// 定位和识别文字结果数组
        /// </summary>
        public list<words_result> words_result { get; set; }

        public class words_result
        {
            /// <summary>
            /// 图片中文字段四个顶点位置(矩形范围)
            /// </summary>
            public list<xy> vertexes_location { get; set; }
            /// <summary>
            /// 可选
            /// 行置信度信息;如果输入参数 probability = true 则输出
            /// </summary>
            public probability probability { get; set; }
            /// <summary>
            /// 每个字
            /// </summary>
            public list<chars> chars { get; set; }
            /// <summary>
            /// 最小细粒度顶点坐标
            /// </summary>
            public list<xy> min_finegrained_vertexes_location { get; set; }
            /// <summary>
            /// 细粒度顶点坐标,多边形
            /// </summary>
            public list<xy> finegrained_vertexes_location { get; set; }
            /// <summary>
            /// 文字在图片中的相对位置
            /// </summary>
            public location location { get; set; }
            /// <summary>
            /// 识别出的文字
            /// </summary>
            public string words { get; set; }
            /// <summary>
            /// 坐标
            /// </summary>
            public class xy
            {
                public int x { get; set; }
                public int y { get; set; }
            }
            /// <summary>
            /// 行置信度
            /// </summary>
            public class probability
            {
                /// <summary>
                /// 行置信度平均值方差
                /// </summary>
                public double variance { get; set; }
                /// <summary>
                /// 行置信度平均值
                /// </summary>
                public double average { get; set; }

                /// <summary>
                /// 行置信度最小值
                /// </summary>
                public double min { get; set; }
            }
            /// <summary>
            /// 单个文字
            /// </summary>
            public class chars
            {
                /// <summary>
                /// 识别的单个文字
                /// </summary>
                public char char { get; set; }
                /// <summary>
                /// 该文字范围(矩形)
                /// </summary>
                public location location { get; set; }
            }
        }
        public class location
        {
            public int left { get; set; }
            public int top { get; set; }
            public int width { get; set; }
            public int height { get; set; }
        }
    }
}

可用控制台进行检验

 static void main(string[] args)
        {
            streamreader streamreader = new streamreader(system.io.file.openread(@"json文件位置"));
            string str = "";
            string jsonstr;
            while ((jsonstr = streamreader.readline()) != null)
            {
                str += jsonstr;
            }

            generalmodel generalmodel = jsonconvert.deserializeobject<generalmodel>(str);

            console.writeline("图片id:" + generalmodel.log_id);
            console.writeline("图像方向:" + generalmodel.direction);
            console.writeline("检测语言为:" + generalmodel.language);
            console.writeline("有几个结果:" + generalmodel.words_result_num);

            foreach (var item in generalmodel.words_result)
            {

                console.writeline("识别结果:" + encoding.utf8.getstring(encoding.utf8.getbytes(item.words)));
                foreach (var itemi in item.vertexes_location)
                {
                    console.writeline("{x:" + itemi.x + ";y:" + itemi.y + "}");
                }
                console.writeline("probability:可信度:" + "行置信度平均值" + item.probability.average + ";行置信度平均值方差:" + item.probability.variance + ";行置信度平均值最小值:" + item.probability.min);
                foreach (var itemi in item.chars)
                {
                    console.writeline(itemi.char);
                    console.writeline("位置:  left:" + itemi.location.left + ";  height: " + itemi.location.height + "top: " + itemi.location.top + "; width: " + itemi.location.width);
                }
            }

            console.readkey();