简体   繁体   中英

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. 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. How can I overcome this problem?

You can add a JsonProperty attribute to class properties. Like this:

public class BehanceData
{
  [JsonProperty("115")]
  public string _115 { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM