0

I am working on an app where I have AFNetworking fetching JSON requests from the my server. Now JSON is dynamically created based upon the POST variables I send from my app.

I was wondering when I get the following error message

JSON text did not start with array or object and option to allow fragments not set.

Is there a way to adapt my code so that I can actually see in the logger what the returned JSON request looks like. I have a feeling that there is a warning popping up in my PHP that is throwing off the JSON but I am not sure what it is.

Here is my code, it would make it so much easier if I could lets say NSLog the body content.

[manager POST:@"__MY__URL__" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

    } progress:nil success:^(NSURLSessionDataTask *operation, id responseObject) {

        NSLog(@"Success: %@", responseObject);

        if([[responseObject objectForKey:@"state"] isEqualToString:@"success"]){

            //[self performSegueWithIdentifier:@"client_choose_ad" sender:self];

        }else {

            [self alertError:@"Unable To Create Advert" alertMessage:[responseObject objectForKey:@"message"]];

        }

    } failure:^(NSURLSessionDataTask *operation, NSError *error) {

        NSLog(@"Error: %@", error);


    }];
ORStudios
  • 3,157
  • 9
  • 41
  • 69
  • Maybe not the answer to your question but I would use something like Chares (https://www.charlesproxy.com/) to debug network traffic. Then you will know exacly what is sent and received. It has saved me alot of time and headache – Erik Johansson Feb 02 '16 at 10:29
  • Hi, I am not sure if that will work if I am testing on my IPhone device. – ORStudios Feb 02 '16 at 10:40
  • That's true, the proxy will only work on the simulator – Erik Johansson Feb 02 '16 at 10:42

1 Answers1

1

Maybe printing the raw data of the request is what you are looking for.

How to print AFNetworking request as RAW data

Community
  • 1
  • 1
Erik Johansson
  • 1,188
  • 1
  • 8
  • 22