[英]Null value after json deserialization on windows phone
I am using the Json.DeserializeObject method in windows phone, inorder to deserialize json, the problem I am having is one of the variable names, in the json has a space and I just can't get it to deserialize. 我在Windows Phone中使用Json.DeserializeObject方法,以反序列化json,我遇到的问题是变量名之一,json中有一个空格,我只是无法反序列化。 it returns a null the whole time, and if I view the raw json it does contain a value
它一直都返回null,如果我查看原始的json,它确实包含一个值
part of raw json: 原始json的一部分:
\"Service Provider\":Test\"
When I try to generate a class for the json into which it needs to be deserialized, the Service Provider section tells me "Invalid Name" and that obviously doesn't work in C# as a variable name, but I believe the variable name can be anything: 当我尝试为需要反序列化的json生成一个类时,服务提供者部分会告诉我“无效名称”,这显然在C#中不能用作变量名,但是我相信变量名可以是任何东西:
public string __invalid_name__Service Provider { get; set; }
current code: 当前代码:
public string Service_Provider { get; set; }
Using Json.Net , Just decorate your property with "JsonProperty" Attribute 使用Json.Net ,只需使用“ JsonProperty”属性装饰属性
string json = @"{""Service Provider"":""Test""}";
var obj = JsonConvert.DeserializeObject<TempObject>(json);
public class TempObject
{
[JsonProperty("Service Provider")]
public string ServiceProvider;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.