我有以下想要提取的 json 响应。我以前从未使用过 json 概念。只想知道如何使用 DataContractJsonSerializer 提取下面的 json 响应,以便我可以提取长名、短名或任何其他级别的属性。
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true
我编写的代码不返回元素值:
var ms = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));
DataContractJsonSerializer stdserialize = new DataContractJsonSerializer(typeof(Address));
Address stuser = (Address)stdserialize.ReadObject(ms);
//############################################################################################################################
[DataContract]
public class Address
{
[DataMember(Name = "long_name")]
public string address1;
[DataMember(Name = "short_name")]
public string shortaddress;
[DataMember(Name = "formatted_address")]
public string formattedtaddress;
[DataMember(Name = "lat")]
public string latitude;
[DataMember(Name = "long")]
public string latitude;
}
//##############################################################################################################################
[DataContract]
public class result
{
[DataMember(Name = "results")]
public string totalResult { get; set; }
[DataMember(Name = "address_components")]
public Dictionary<string, Address> merchants { get; set; }
}
//###################################################################################################################
任何帮助将不胜感激。