我尝试使用 Monotouch 通过 HttpWebRequest 对象获取 JSON 数据。它在 iPhone 模拟器中运行良好,我得到了 JSON。但是当我在设备中运行应用程序时,当调用 Web 服务时,我总是返回 XML 而不是 JSON。
从 iPhone 运行时,是否有任何特定的配置参数需要设置才能以 JSON 格式获得结果?我在 iPhone 5 和 ios 6 上运行它。
这是我的代码..
var request = HttpWebRequest.Create(String.Format (@"{0}/GetActiveProductCountAfterID/filter?minID={1}",baseUrl, lastProductNumberInDatabase));
Logger.Debug("Request URL is: " + request.RequestUri);
request.ContentType = @"application/json";
request.Method = "GET";
try{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string content = reader.ReadToEnd();
........
当我在模拟器中运行时,我将内容作为整数..例如:3456
但是当我从 iPhone 上运行它时,我得到了
<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">3456</int>