Behance API 属性 名字是数字
Behance API property name is number
我正在使用请求 link 来获取用户的项目。它 returns 许多以下内容:
{
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"
}}
但 covers
和 images
数组有问题。它们的名称是数字,当我使用 Json.Net 将它们反序列化为与返回的 JSON 字符串上的字段相同的 class 时,会出现问题,因为 属性在 C# classes 中名称不能是数字,当我将名称更改为字母数字时(例如 BehanceImg_138
而不是仅 138
),这次 Json.Net 可以' t 匹配 JSON 字符串中的字段并且 BehanceImg_138 变为空,尽管它在 JSON 字符串中不为空。我该如何克服这个问题?
您可以将 JsonProperty
属性添加到 class 属性。像这样:
public class BehanceData
{
[JsonProperty("115")]
public string _115 { get; set; }
}
我正在使用请求 link 来获取用户的项目。它 returns 许多以下内容:
{
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"
}}
但 covers
和 images
数组有问题。它们的名称是数字,当我使用 Json.Net 将它们反序列化为与返回的 JSON 字符串上的字段相同的 class 时,会出现问题,因为 属性在 C# classes 中名称不能是数字,当我将名称更改为字母数字时(例如 BehanceImg_138
而不是仅 138
),这次 Json.Net 可以' t 匹配 JSON 字符串中的字段并且 BehanceImg_138 变为空,尽管它在 JSON 字符串中不为空。我该如何克服这个问题?
您可以将 JsonProperty
属性添加到 class 属性。像这样:
public class BehanceData
{
[JsonProperty("115")]
public string _115 { get; set; }
}