[英]Behance API property name is number
I'm using a request link to get the projects of a user. 我正在使用请求链接来获取用户的项目。 It returns many following: 它返回以下内容:
{
id: 123456,
name: "Deneme 2",
published_on: 1427213730,
created_on: 1427213604,
modified_on: 1427213730,
url: "https://www.behance.net/gallery/123456/trial-2",
privacy: "public",
fields: [
"Film"
],
covers: {
115: "abc.com/xyz.jpg",
202: "abc.com/xyz.jpg",
230: "abc.com/xyz.jpg",
404: "abc.com/xyz.jpg"
}}
but covers
and images
arrays are problematic. 但是covers
和images
阵列有问题。 Their names are numeric, and when I use Json.Net to deserialize them to a class that is identical to the fields on the returning JSON string, there occurs a problem because property names can't be numeric in C# classes, and when I change the names to alphanumerics (such as BehanceImg_138
instead of only 138
), this time Json.Net can't match the field in the JSON string and BehanceImg_138 becomes null, although it's not null in JSON string. 它们的名称是数字,当我使用Json.Net将它们反序列化为与返回的JSON字符串上的字段相同的类时,会出现问题,因为属性名称在C#类中不能为数字,并且当我更改时字母数字的名称(例如BehanceImg_138
而不是仅138
),这次Json.Net无法匹配JSON字符串中的字段,并且BehanceImg_138变为null,尽管在JSON字符串中不为null。 How can I overcome this problem? 我该如何克服这个问题?
You can add a JsonProperty
attribute to class properties. 您可以将JsonProperty
属性添加到类属性。 Like this: 像这样:
public class BehanceData
{
[JsonProperty("115")]
public string _115 { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.