我试图从REST服务反序列化到C#中强类型类 - 但是我遇到了同样的问题在这篇文章中有: How do I output this JSON value where the key starts with a number?解析JSON响应,其中对象以c中的数字开头#
但是我有这个问题,你不能在c#中用一个数字开始一个变量名 - 这意味着该级别的类只是反序列化为null。
我需要知道如何进入对象并将它们反序列化到C#类中。
我当前的代码如下:
public static async Task<T> MakeAPIGetRequest<T>(string uri)
{
Uri requestURI = new Uri(uri);
using (HttpClient client = new HttpClient())
{
HttpResponseMessage responseGet = await client.GetAsync(requestURI);
if (responseGet.StatusCode != HttpStatusCode.OK)
{
throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).",
responseGet.StatusCode,
responseGet.Content));
}
else
{
string response = await responseGet.Content.ReadAsStringAsync();
T objects = (JsonConvert.DeserializeObject<T>(response));
return objects;
}
}
}
编辑:我不能更改服务正在推动数据备份
发布样品JSON。 –
我认为这将有助于http://stackoverflow.com/questions/24218536/deserialize-json-that-has-some-property-name-starting-with-a-number – HebeleHododo
@HebeleHododo非常感谢你! –