如何解决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 举报,一经查实,本站将立刻删除。