【发布时间】:2014-07-21 20:52:05
【问题描述】:
我有一个 RESTFUL API 服务,它返回具有唯一 ID 号的位置的城市、州、邮编等。在我获取数据的函数中,我返回了一个名为“List”的数组。例如,数组结果为<string>Kansas City</string>。
我怎样才能拥有像<City>Kansas City</City> <State>MO</State>. 这样的客户标签?
我在函数中的代码的一个sn-p是:
string [] List = new string [7];
List[0]= City;
List[1]= County;
List[2]= State;
List[3]=Postal;
List[4]=isDefaultLocation;
List[5]=locationId;
List[6]=AtlasKey;
return List;
使用 example.com/locations/id/10000 以 XML 格式返回结果
【问题讨论】:
-
那么您如何从 API 返回数据?
-
您需要实现一个类来封装您要通过网络发送的所有数据,然后使用 DataContract 或 XmlSerializer 发出所需的 XML 输出。
标签: c# web-services tags restful-url