开发者

Parse JSON result into NSString or similar "primitive" datatypes in RestKit

I'm a beginner to RestKit and I'm finding difficult to get the hang of it, beats using standard cocoa to do webservice response parsing, but still feels lightyears behind .net or java...

Anyhow, to the point. I have a WCF webservice which returns something like this:

{"GetSiteMapResult":"iVBORw0KGgoAAAANSUhEUgAAB\/cAAAf3CAIAAACicn4JAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAP+lSURBVHhe7P0JoF1HcSeMS2\/X0y5ZepK8St5ly7HxgsxiB2TH"}

GetSiteMapResult follo开发者_开发技巧wed by a large string.

How can I parse this into an NSString using ReskKit? I tried adding a mapping, but I'm not sure what the code would be for this, for instance all examples are along the lines of:

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[myClass class]];
[mapping mapKeyForPath:@"node" toAttribute:@"attributeInMyClass"];
[[RKObjectManager sharedManager].mappingProvider setMapping:mapping forKeyPath:@"RootNodeInReturnJSON"];

But since this is an object I'm returning in the service response, only a string, I'm not sure how to do this.


You do not need RestKit to parse such a simple response, moreover i guess RestKit can not parse into NSString. RestKit is a real life saver when you have more complicated JSON responses. In order to parse this response i would create a class with one string ivar & map the response accordingly.

However, i'd recommend using JSONKit to parse simple responses from your webservice api. You may also take a look at the famous ASIHTTP library which will help you for sure with the handling of HTTP communication.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜