oData Objective-C 添加 JSON 流
我尝试从我的 odata 服务器添加 Json strem。 它与 jQuery 一起工作得很好,但在 Objective-C 中只返回 xml。
我尝试这个:
DataModel *proxy = [[DataModel alloc] initWithUri:@"http://www.example.com/odata/odata.svc" credential:nil];
[proxy addHeader:@"Accept" headerValue:@"application/json, text/javascript, */*; sq=0.01"];
QueryOperationResponse *response = [proxy execute:@"Example"];
NSMutableArray *array = [response getResult];
它不起作用。
我该怎么办?
谢谢 格温宁
I try to add a Json strem form my odata server.
It work fine with jQuery, but in objective-c ther is only xml returned.
I try this :
DataModel *proxy = [[DataModel alloc] initWithUri:@"http://www.example.com/odata/odata.svc" credential:nil];
[proxy addHeader:@"Accept" headerValue:@"application/json, text/javascript, */*; sq=0.01"];
QueryOperationResponse *response = [proxy execute:@"Example"];
NSMutableArray *array = [response getResult];
It doesn't work.
How can I do?
thanks
Gwennin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果返回的类型是 Collection<>在某种程度上,OData 库会为您完成这项工作,并将其转换为 Objective-C 中正确实体的数组。
如果返回简单类型,则解析结果。一个示例是使用 XPath 查询(尽管对于我的服务,我必须从返回的 XML 中删除 Odata 返回的几个不受支持的根元素属性)。
如果您选择使用 Xpath,我喜欢这段代码: http ://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
If the returned type is a Collection<> of some sort, the OData library does the work for you and converts it to an array of the correct Entity in Objective-C.
If you return a simple type, parse the result. An example is using XPath queries (although for my service, I had to remove from the returned XML a couple of unsupported root element attributes that Odata returned).
If you chose to use Xpath,I love this code: http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
xml 是 odata 将返回的内容。您将需要解析结果。这是一个很棒的教程的链接。
http://www .raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
xml is what odata will return. you will need to parse the results. Here is a link to a great tutorial for doing that.
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project