2011-02-19 53 views
0

我试图反序列化由yahoo api返回的复杂对象,但我没有经过多少实验。我创建了一个基本对象,但与我的反序列化json的细节不匹配。有人可以帮助我构建正确的对象,以便在反序列化之后匹配返回的响应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 } }  
*/ 

Basic对象

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; 

} 

回答

0

它返回的地点集合,你占了吗?你也可以尝试这样的事情,看看它产生了什么。 http://jsonclassgenerator.codeplex.com/

+0

Derek,这是一个不错的工具,但我使用ServiceStack序列化程序的JSON这个工具是牛顿软件。 – user325558

+0

您是否找到解决问题的方法? –