use*_*331 8 xml sql asp.net json objective-c
我有一个问题,即通过ASP.NET从SQL数据库获取数据,然后将数据传递给Objective-C.目前我只是使用SQL select语句通过ASP.NET从数据库中获取数据,ASP.NET返回如下数据:
<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89 xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<KeyValueOfstringPunchListCellModel84zsBx89>
<Key>ORC0023</Key>
<Value xmlns:d3p1="http://schemas.datacontract.org/2004/07/LHS.Models">
</Value>
</KeyValueOfstringPunchListCellModel84zsBx89>
</ArrayOfKeyValueOfstringPunchListCellModel84zsBx89>
Run Code Online (Sandbox Code Playgroud)
然后在Objective-C中,我将数据放入NSDictionary中,如下所示:
NSDictionary *punchList = [[NSDictionary alloc]initWithDictionary:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&myError]];
Run Code Online (Sandbox Code Playgroud)
一切都在这里按预期工作.
我现在正在做的是创建一个返回XML的存储过程,并让ASP.NET返回XML(这里的所有内容都已完成并按预期工作)XML如下所示:
<KeyValueOfstringPunchListCellModel84zsBx89>
<Key>ORC0023</Key>
<Value>
</Value>
</KeyValueOfstringPunchListCellModel84zsBx89>
</ArrayOfKeyValueOfstringPunchListCellModel84zsBx89>
Run Code Online (Sandbox Code Playgroud)
现在对于Objective-C粉丝,您知道除非您使用第三方项目/库,否则您无法在NSDictionary中使用XML.
现在我的问题是,我是否重做了我的存储过程以返回JSON,还是有另一种方法可以解决这个问题?
我的最终目标是尽可能快地完成流程,并且SQL查询很大并且返回很多行.
你应该
1)重做您的存储过程并返回原始数据。
2) 让 asp.net 处理数据格式,因为有些客户端可能需要 JSON,而另一些客户端可能更喜欢 xml。所以如果你要走 JSON 路线,你可以从 MVC 控制器返回 JSON 结果,即
public JsonResult GetData()
{
var temp = new {
name = "hello world"
};
return this.Json(temp)
}
Run Code Online (Sandbox Code Playgroud)
或使用 Web api 创建 Web 服务。
由于你有一个很大的结果集,你应该尝试使用 JSON,它比 xml 更简洁,因此会消耗更少的资源
| 归档时间: |
|
| 查看次数: |
205 次 |
| 最近记录: |