为反序列化的json响应创建一个匹配详细信息的对象

时间:2011-02-19 15:27:05

标签: c# json deserialization

我尝试反序列化由yahoo api返回的复杂对象,但我没有经过实验。我创建了一个基本对象但是与我反序列化的json的细节不匹配。有人可以帮我构建正确的对象,该对象将在反序列化后与此响应json中的返回项匹配。这里Json和我的基本对象不匹配细节。感谢。

/*
# {  
# "places":{  
#   "place":[  
#     {  
#       "woeid":12521721,  
#       "placeTypeName":"Airport",  
#       "placeTypeName attrs":{  
#         "code":14 },  
#       "name":"San Francisco International Airport",  
#       "country":"United States",  
#       "country attrs":{  
#         "type":"Country",  
#         "code":"US" },  
#       "admin1":"California",  
#       "admin1 attrs":{  
#         "type":"State",  
#         "code":"US-CA" },  
#       "admin2":"San Mateo",  
#       "admin2 attrs":{  
#         "type":"County",  
#         "code":"" },  
#       "admin3":"",  
#       "locality1":"Millbrae",  
#       "locality1 attrs":{  
#         "type":"Town" },  
#       "locality2":"",  
#       "postal":"94128",  
#       "postal attrs":{  
#         "type":"Zip Code" },  
#       "centroid":{  
#         "latitude":37.614712,  
#         "longitude":-122.391808 },  
#       "boundingBox":{  
#         "southWest":{  
#           "latitude":37.601822,  
#           "longitude":-122.408089 },  
#         "northEast":{  
#         "latitude":37.627602,  
#         "longitude":-122.375526 } },  
#       "uri":"http:\/\/where.yahooapis.com\/v1\/place\/12521721",  
#       "lang":"en-us" } ],  
#   "start":0,  
#   "count":1,  
#   "total":1 } }       
*/

基本对象

public class YahooPlace
{
    public string woeid
    {
        get { return this._woeid; }
        set { this._woeid = value; }
    }
    public string placeTypeName
    {
        get { return this._placeTypeName; }
        set { this._placeTypeName = value; }
    }
    public string placeTypeName_attrs
    {
        get { return this._placeTypeName_attrs; }
        set { this._placeTypeName_attrs = value; }
    }
    public string country
    {
        get { return this._country; }
        set { this._country = value; }
    }
    public string country_attrs
    {
        get { return this._country_attrs; }
        set { this._country_attrs = value; }
    }
    public string admin1
    {
        get { return this._admin1; }
        set { this._admin1 = value; }
    }
    public string admin1_attrs
    {
        get { return this._admin1_attrs; }
        set { this._admin1_attrs = value; }
    }
    public string admin2
    {
        get { return this._countryCode; }
        set { this._countryCode = value; }
    }
    public string admin2_attrs
    {
        get { return this._admin2_attrs; }
        set { this._admin2_attrs = value; }
    }
    public string admin3
    {
        get { return this._admin3; }
        set { this._admin3 = value; }
    }
    public string locality1
    {
        get { return this._locality1; }
        set { this._locality1 = value; }
    }
    public string locality1_attrs
    {
        get { return this._locality1_attrs; }
        set { this._locality1_attrs = value; }
    }
    public string locality2
    {
        get { return this._locality2; }
        set { this._locality2 = value; }
    }
    public string postal
    {
        get { return this._postal; }
        set { this._postal = value; }
    }
    public string postal_attrs
    {
        get { return this._postal_attrs; }
        set { this._postal_attrs = value; }
    }
    public string centroid
    {
        get { return this._centroid; }
        set { this._centroid = value; }
    }
    public string boundingBox
    {
        get { return this._boundingBox; }
        set { this._boundingBox = value; }
    }
    public string uri
    {
        get { return this._uri; }
        set { this._uri = value; }
    }
    public string lang
    {
        get { return this._lang; }
        set { this._lang = value; }
    }

    private string _admin1_attrs,_admin2_attrs, _admin3, _locality1, _locality1_attrs, _locality2, _postal, _postal_attrs, _centroid, _lang, _uri, _boundingBox, _countryCode, _admin1, _country_attrs, _country, _placeTypeName_attrs, _placeTypeName, _woeid;

}

1 个答案:

答案 0 :(得分:0)

它正在返回一个地方的集合,你在考虑那个?你也可以尝试这样的东西,看看它产生了什么。 http://jsonclassgenerator.codeplex.com/