C#无法反序列化当前JSON对象例如{“ name”:“ value”}

如何解决C#无法反序列化当前JSON对象例如{“ name”:“ value”}

我正在尝试反序列化JSON响应,我已经对此进行了大量搜索,并且我知道有很多与此相关的帖子,但没有一个女巫起作用。

在下面,您将看到JSON响应:

{
"id": "xxx","name": "xxx","value": 138000,"type": "sales","tags": "","external_id": "xxx","external_client_id": "api","external_editor_type": "","external_editor_id": "","company_name": "","company_number": "","company_id": "","company_logo_url": "","unique_id": 0,"is_selfsign": true,"is_signing_biometric": true,"is_signing_initials": false,"is_signing_forward": true,"is_identify_recipient": false,"is_private": false,"status": "signed","send_date": "2020-08-14T09:46:04+00:00","sign_date": "2020-08-16T19:51:30+00:00","created_at": "2020-08-14T09:45:21+00:00","user_id": "9n6kgd3p","sender_name": "xxx","sender_thumb_url": "","sender_email": "xxx","email_send_template_id": "xxx","parent_id": "","email_send_subject": "xxx","email_send_message": "xxx","is_signing": true,"is_signing_order": false,"is_signed": true,"expiration_date": "2020-08-28T21:59:00+00:00","is_scheduled_sending": false,"scheduled_sending_time": null,"is_reminder_sending": false,"is_video": false,"video_id": null,"is_auto_comment": false,"auto_comment_text": "","is_auto_comment_email": false,"auto_comment_email": "","entity_auto_comment_text": "","field_count": 0,"contract_start_date": null,"contract_end_date": null,"thumb_url": "xxx","preview_url": "xxx","download_url": "xxx","recipients": [
    {
        "fullname": "xxx","first_name": "xxx","last_name": "xxx","email": "xxx","title": "","note": "","gender": "m","mobile": "","thumb_url": "","role": "signer","order_num": "1"
    }
]

}

我正在使用的类:

public class Recipient
{
    public string fullname { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public string email { get; set; }
    public string title { get; set; }
    public string note { get; set; }
    public string gender { get; set; }
    public string mobile { get; set; }
    public string thumb_url { get; set; }
    public string role { get; set; }
    public string company_name { get; set; }
    public string company_number { get; set; }
    public string status { get; set; }
    public string order_num { get; set; }
}

public class Root
{
    public string id { get; set; }
    public string name { get; set; }
    public int value { get; set; }
    public string type { get; set; }
    public string tags { get; set; }
    public string external_id { get; set; }
    public string external_client_id { get; set; }
    public string external_editor_type { get; set; }
    public string external_editor_id { get; set; }
    public string company_name { get; set; }
    public string company_number { get; set; }
    public string company_id { get; set; }
    public string company_logo_url { get; set; }
    public int unique_id { get; set; }
    public bool is_selfsign { get; set; }
    public bool is_signing_biometric { get; set; }
    public bool is_signing_initials { get; set; }
    public bool is_signing_forward { get; set; }
    public bool is_identify_recipient { get; set; }
    public bool is_private { get; set; }
    public string status { get; set; }
    public DateTime send_date { get; set; }
    public DateTime sign_date { get; set; }
    public DateTime created_at { get; set; }
    public string user_id { get; set; }
    public string sender_name { get; set; }
    public string sender_thumb_url { get; set; }
    public string sender_email { get; set; }
    public string email_send_template_id { get; set; }
    public string parent_id { get; set; }
    public string email_send_subject { get; set; }
    public string email_send_message { get; set; }
    public bool is_signing { get; set; }
    public bool is_signing_order { get; set; }
    public bool is_signed { get; set; }
    public DateTime expiration_date { get; set; }
    public bool is_scheduled_sending { get; set; }
    public object scheduled_sending_time { get; set; }
    public bool is_reminder_sending { get; set; }
    public bool is_video { get; set; }
    public object video_id { get; set; }
    public bool is_auto_comment { get; set; }
    public string auto_comment_text { get; set; }
    public bool is_auto_comment_email { get; set; }
    public string auto_comment_email { get; set; }
    public string entity_auto_comment_text { get; set; }
    public int field_count { get; set; }
    public object contract_start_date { get; set; }
    public object contract_end_date { get; set; }
    public string thumb_url { get; set; }
    public string preview_url { get; set; }
    public string download_url { get; set; }
    public List<Recipient> recipients { get; set; }
}

我正在尝试像这样反序列化

var data = JsonConvert.DeserializeObject<List<Root>>(response.Content);
email_send_message = data[0].email_send_subject;
Console.WriteLine(email_send_subject + " " + email_send_message);

我收到此错误:

无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型'System.Collections.Generic.List`1 [TelerikWinFormsApp1.GetAcceptAPI + DownloadSignedDocument + Root]',因为该类型需要JSON数组(例如[1,2,3])正确反序列化。 要解决此错误,可以将JSON更改为JSON数组(例如[1,3]),也可以更改反序列化类型,使其成为普通的.NET类型(例如,不像整数这样的原始类型,也不像这样的集合类型)数组或列表),可以从JSON对象反序列化。还可以将JsonObjectAttribute添加到类型中,以强制其从JSON对象反序列化。

谁能告诉我我在做什么错,或者至少将我指向正确的方向?

谢谢!

解决方法

更新此

SELECT      a.*,b.*,st_intersection(a.geom,b.geom) as geom
FROM        a,b
WHERE       st_intersects(a.geom,b.geom)

from PIL import Image
import numpy as np
from wordcloud import WordCloud
mask = np.array(Image.open('pentagon.jpg'))
wc = WordCloud(mask=mask,scale=5,background_color='white',collocations=False,max_words=500,max_font_size=256)
wc.generate_from_frequencies(k)
wc.prefer_horizontal=0.7
plt.imshow(wc,interpolation="bilinear")
plt.axis('off')
plt.show()

您的Json对象是单个对象,但是您试图反序列化为List,这是错误的

,

如何使用JsonSerializer.Deserialize (response.Content)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-