2

JavaScriptSerializer.Deserializeを使用してyoutubeapiからJSONを逆シリアル化しています。JSONで「default」という名前のJSONフィールドを逆シリアル化するにはどうすればよいですか? C#

{ 
"kind": "youtube#videoListResponse", 
"etag": "\"kiOs9cZLH2FUp6r6KJ8eyq_LIOk/9dlz1IIYCkI6XFpNy28ZfHloSKY\"", 
"pageInfo": { 
    "totalResults": 1, 
    "resultsPerPage": 1 
}, 
"items": [ 
    { 
    "kind": "youtube#video", 
    "etag": "\"kiOs9cZLH2FUp6r6KJ8eyq_LIOk/xNIcXxr4UjrZ1ZnL0lGaAAqLc4k\"", 
    "id": "r8Ni2m3ro30", 
    "snippet": { 
    "publishedAt": "2013-09-25T17:49:08.000Z", 
    "channelId": "UCeq7mOAcfee86UYyG8SCgvw", 
    "title": "Long-Lasting Residual with Capreno Corn Herbicide", 
    "description": "Watch growers talk about their experience with Capreno® corn herbicide's long-lasting residual. During unforgiving weather conditions, Capreno postemergence herbicide delivers season-long control of the toughest weeds to deliver an amazing end-of-season clean.", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/r8Ni2m3ro30/default.jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/r8Ni2m3ro30/mqdefault.jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/r8Ni2m3ro30/hqdefault.jpg", 
     "width": 480, 
     "height": 360 
    } 
    } 
    } 
    } 
] 
} 

JSONのデータ構造を実装するクラスを作成しました。唯一の問題はサムネイルです。私は次のクラスを作成しました:

public class Thumbnails 
{ 
    public Thumbnail default { get; set; } 
    public Thumbnail medium { get;set; } 
    public Thumbnail high { get;set; } 
} 

public class Thumbnail 
{ 
    public string url { get; set; } 
    public int width { get;set; } 
    public int height { get; set; } 
} 

しかし、私はパラメータ "default"の名前を付けることはできません。私はJSONを変更することはできませんが、私はこのデフォルトが必要です。私は別の名前を付けてもそれをデシリアライズしません。 「中」と「高」は正しくデシリアライズされます。

答えて

5

キーワードをエスケープするには@を使用してください。

public Thumbnail @default { get; set; } 
関連する問題