これがシリアル化されると、結果のリストにゼロの結果が得られます。私は実際には、結果のジオメトリを取得しようとしていますが、何らかの理由ですべての結果が表示されていないと私は、カウントを行うとき、私はここにxml to c#クラスが正しくシリアル化されない
0は、XMLの抜粋で取得
<?xml version="1.0" encoding="UTF-8"?>
<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Premier Inn Manchester Deansgate Locks</name>
<vicinity>Medlock Street, Manchester</vicinity>
<type>lodging</type>
<type>restaurant</type>
<type>food</type>
<type>point_of_interest</type>
<type>establishment</type>
<geometry>
<location>
<lat>53.4713048</lat>
<lng>-2.2474693</lng>
</location>
<viewport>
<southwest>
<lat>53.4711143</lat>
<lng>-2.2475661</lng>
</southwest>
<northeast>
<lat>53.4718764</lat>
<lng>-2.2473777</lng>
</northeast>
</viewport>
</geometry>
C#
if (webResponse.error == null)
{
print(webResponse.text);
PlacesApiQueryResponse placesObject = LoadFromText(webResponse.text);
print(placesObject.results.Count);
foreach(var entity in placesObject.results)
{
print(entity.geometry.location.lat + " | " + entity.geometry.location.lng);
}
}
else
{
print(webResponse.error);
}
}
public static PlacesApiQueryResponse LoadFromText(string text)
{
var serializer = new XmlSerializer(typeof(PlacesApiQueryResponse), new XmlRootAttribute("PlaceSearchResponse"));
return serializer.Deserialize(new StringReader(text)) as PlacesApiQueryResponse;
}
}
public class Location
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Geometry
{
public Location location { get; set; }
}
public class OpeningHours
{
public bool open_now { get; set; }
}
public class Photo
{
public int height { get; set; }
public List<object> html_attributions { get; set; }
public string photo_reference { get; set; }
public int width { get; set; }
}
public class AltId
{
public string place_id { get; set; }
public string scope { get; set; }
}
public class Result
{
public Geometry geometry { get; set; }
public string icon { get; set; }
public string id { get; set; }
public string name { get; set; }
public OpeningHours opening_hours { get; set; }
public List<Photo> photos { get; set; }
public string place_id { get; set; }
public string scope { get; set; }
public List<AltId> alt_ids { get; set; }
public string reference { get; set; }
public List<string> types { get; set; }
public string vicinity { get; set; }
public string rating { get; set; }
}
public class PlacesApiQueryResponse
{
public List<object> html_attributions { get; set; }
public List<Result> results { get; set; }
public string status { get; set; }
}
元のC#コードで 'if(webResponse.error == null)'の前に来たことはありますか?また、あなたは何をシリアライズしていますか?シリアライズはどこですか? –
"PlacesApiQueryResponse"クラスの名前を "PlaceSearchResponse"に変更するか、クラスにXMLElementデコレーションを追加します。 –
@Telansこれは問題ではありません。 –