how to log raw JSON response with RestKit 0.2x - iphone

with RestKit 0.2x the RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); statement displays various mapping info with the returned JSON response but all things are mixed up together which is hard for me to extract the raw JSON body alone.
is there a way to log ONLY the returned JSON body without extra info with it ?
thanks in advance.

You can add a logging code in RKNSJSONSerialization's method
+ (id)objectFromData:(NSData *)data error:(NSError **)error
or better solution would be to subclass RKNSJSONSerialization and add the logging code.

It isn't clear exactly what you're looking for. The trace log does print the entire JSON before the mapping starts.
Alternatively, you could edit RKMapperOperation to do additional logging or just use AFNetworking to download and log the JSON.

Related

Objective C error 3840 - bad JSON apparently but it validates with JSlint

I have read around and this error seems to be from bad JSON. Easy enough, here is my JSON
{"year":"2012","wheels":"Standard","trans":"Unknown"}
My issue is, this appears to be correct, and when I run it through JSON lint it returns vaild. I have also used cURL to download this page and used json_decode() to read it...worked fine.
Here is an example page: http://drivingthenation.com/app/carlist/getVinDtn.php?v=JA3215H1C**M&f=v
I ran it through HTTPScoop and the only thing the response text returned was
{"year":"2012","wheels":"Standard","trans":"Unknown"}
On the objective-c end I am using NSURL and NSData to get the URL, and then NSJSONSerialization. I can print out before NSJSONSerialization and see that it is infact getting data, but this error only occurs when I try to format it into JSON. Any thoughts?
The NSJSONSerialization class, by default, expects the input to be not just valid JSON, but a valid JSON object. If you want to read something that's not an object, you need to specify the NSJSONReadingAllowFragments option to the reader.

Restkit : Download a file on system

I have a really hard time to find how downloading a file with the restkit framework ?
I've got a webservice (with base64 auth), which return a file.
When i do a regular "get" call, i did receive the stream (with good mime/types), but i can't find a way of getting the data, to make a NSData, and register my file. The response object only have a bodyString and bodyJSON, but no bodyDATA.
I haven't used RestKit, but accoding to their API documentation the RKResponse object has a body property that is of type NSData.

NSXMLParsing data, retriving data problem during parsing

i am creating an app in which i want to take xmldata using webservices.
i am using NSXMLParser.
i get the data in respond data when this below method calling
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//NSLog(#"====== Connection ========");
[catalogData appendData:data];
//NSLog(#"catalog data-=-=-=-=-=-=-%#", catalogData);
}
but when i parse this catalogData in finishloading method i get the null array.
i don't know what the problem is,
this is my XML data
3
1
1
<sPagRichiestaFornitore>
</sPagRichiestaFornitore>
<idCategoria>1</idCategoria>
NSLog your data inside connectionfinishloading then. If you get a proper XML, then you can create the XML parser accordingly.
You can refer the Top Paid Sample app of apple for the NSXMLParser Implementation.
i cannot help with such a small code friend . can you please tell what exactly you get in response if you not getting please check your php file that is on server some problem with that . One thing i suggest you is that once remove this tag from your php file and again try to get response
thanks
hope this helps

Get NSString/NSData object from hardcoded bytes saved as NSString object in webservice response

I am working with the iPhone SDK and I have to process a webservice response I receive from an external service.
The response data consists of an XML string that was UTF8-encoded to a byte array.
This byte array is converted to string
This string is put into a XML wrapper element
The wrapper is returned via an HTTP response
Therefore I need to know how to convert the response data back to the XML string it used to be. Unfortunately, I cannot change the way my response is created, so I have to deal with it somehow.
Example of the raw data I get from the webservice:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><ExportBytesResponse xmlns="http://knowledgepark-ag.com/webservices/">
<ExportBytesResult>PERhdGE+PFJlY29yZCBEQj0iOTk5OTQiIEtleT0iMjA1Mjc0Ij48U2luZ2xlIEl0ZW1JZD0iQVJCUEFLRVQiIFZhbHVlPSIyOTAiIC8+PFNpbmdsZSBJdGVtSWQ9IkhET0tOUiIgVmFsdWU9IjIwNTI3NCIgLz48U2luZ2xlIEl0ZW1JZD0iVkVSQSIgVmFsdWU9IjEuNzEuMzIxMy4xNzU3NyIgLz48U2luZ2xlIEl0ZW1JZD0iRElTIiBWYWx1ZT0iR2VNLCBNw6RyIDEwIDIwMDggIDU6NDFQTTomI3hEO1ouenQuIGV4aXNpdGVydCBrZWluZSBNw7ZnbGljaGtlaXQgZGFzIEJlZW5kZW4gZWluZXMgTW9kdWxzIGR1cmNoIEFiYnJlY2hlbiBvZGVyIEhhcmQtQ2xvc2UtWCB6dSBlcmZhaHJlbi4gQW4gZGllc2VyIFN0ZWxsZSBtw7xzc3RlbiBtZWlzdCBVc2VydmFycyBkZXMgTW9kdWxzIGdlbMO2c2NodCB3ZXJkZW4uIE9kZXIgYW5kZXJlIEF1ZnLDpHVtYWt0aW9uIGR1cmNoZ2Vmw7xocnQgd2VyZGVuLiYjeEE7RUxLRUcgMDYuMDguMjAwOCAwOToyMToxNyYjeEE7JiN4QTsgQmVpc3BpZWxhdWZiYXUgOiYjeEQ7JiN4QTsmbHQ7Q2xv</ExportBytesResult>
</ExportBytesResponse></s:Body>
How do I get back my old xml string representation hidden inside these raw bytes?
Any help is highly appreciated, I feel just stupid right now for not being able to come up with a solution.
Best Regards,
David
ExportBytesResponse is Base64 encoded, so you must first decode that node using something like this.
That will give you an NSString containing the XML. Then you can use NSXMLParser to parse your data.

MGTwitterEngine

I am using mgtwitterEngine to integrate twitter functionality.In my application i want response in XML format so i have done all the changes as metion in readme of mgtwiiter
for example i have done
#define YAJL_AVAILABLE 0
in MGTwitterEngineGlobalHeader.h and
#define USE_LIBXML 1
in MGTwitterEngine.m file and i am checking that API_FORMAT is xml too but whenever i am getting response i am getting in json format.
Please can any one tell me what am i missing? any help would be appreciated.
Thaks
Are you looking at NSLog output for received objects? NSLog output for objects like dictionary or array is similar to JSON format.