iosjsonobjective-cbing

Not able to understand Bing JSON response


My code:

NSString *urlString = [NSString stringWithFormat:@"%@%@%@%@", @"http://api.search.live.net/json.aspx?Appid=am hiding the appid &query=",text,@"&sources=web&web.offset=",offvalue];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
    

The JSON response:

SearchResponse =     {
        Errors =         (
                        {
                Code = 1002;
                HelpUrl = "http://msdn.microsoft.com/en-us/library/dd251042.aspx";
                Message = "Parameter has invalid value.";
                Parameter = "SearchRequest.AppId";
                Value = " am hiding the value";
            }
        );
        Query =         {
            SearchTerms = iphone;
        };
        Version = "2.2";
    };
}

What wrong am I doing here.Can anyone please rectify my query? How to use version 2.2 of the Bing API?


Solution

  • What is the value of 'text', is this one word or multiple words? You'll need to perform URL_Encode on the parameter 'text' in order to have a valid URL.

    See Objective-C and Swift URL encoding Be sure only to have the URL_Encoding on the text-object and not on the whole URL, otherwise "http://" will be encoded as well, resulting in an invalid URL as well

    Eg a space should be %20 , you can verify this by adding a NSLog of the URL