IOS - VCard Data not attaching properly - ios

I'm trying to convert Vcard/vcf information in the form of JSON to an NSData object. When I try to attach the NSData object, it's not displaying properly. Am I missing a conversion step between the JSON information and the NSData object?
if(args[#"attachments"][#"vcf"]){
NSArray *vCard = [RCTConvert NSArray:args[#"attachments"][#"vcf"]];
NSLog(#"%#", vCard);
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:vCard options:kNilOptions error:&error];
NSLog(#"%#", data);
NSString *contactIdentifier = #"kUTTypeVCard";
NSString *contactName = [RCTConvert NSString:args[#"attachments"][#"contactName"]];
[ mcvc addAttachmentData:data typeIdentifier:contactIdentifier filename:contactName];
}
Here is the JSON Object being passed into the state:
data: "BEGIN:VCARD↵VERSION:4.0↵FN:Matthew Marks↵EMAIL;TYP…quot;];PREF=1:Matthewmarks13#gmail.com↵END:VCARD↵"
This is the NSLog of the data:
<5b224245 47494e3a 56434152 445c6e56 45525349 4f4e3a34 2e305c6e 464e3a4d 61747468 6577204d 61726b73 5c6e454d 41494c3b 54595045 3d5b2671 756f743b 776f726b 2671756f 743b2c20 2671756f 743b696e 7465726e 65742671 756f743b 5d3b5052 45463d31 3a4d6174 74686577 6d61726b 73313340 676d6169 6c2e636f 6d5c6e45 4e443a56 43415244 5c6e225d>

Related

Get values from NSDictionary

Hi I'm new to iOS development. I want to get response and add those values to variable.
I tried it but I'm getting below response. I don't understand why there is slashes in this response.
#"[{\"VisitorID\":\"2864983a-e26b-441a-aedf-84e2a1770b8e\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kanasalingam\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]},{\"VisitorID\":\"133bc108-b3bf-468a-9397-e1b0dba449db\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kumar\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]}]"
I tried this :
- (void) sendOtherActiveChats:(NSDictionary *) chatDetails{
NSLog(#"inside sendOtherActiveChats");
NSLog(#"otherDetails Dictionary : %# ", chatDetails);
NSString *VisitorID = [chatDetails objectForKey:#"VisitorID"];
NSString *ProfileID = [chatDetails objectForKey:#"ProfileID"];
NSString *CompanyID = [chatDetails objectForKey:#"CompanyID"];
NSString *VisitorName = [chatDetails objectForKey:#"VisitorName"];
NSString *OperatorName = [chatDetails objectForKey:#"OperatorName"];
NSString *isocode = [chatDetails objectForKey:#"isocode"];
NSLog(#"------------------------Other Active Chats -----------------------------------");
NSLog(#"VisitorID : %#" , VisitorID);
NSLog(#"ProfileID : %#" , ProfileID);
NSLog(#"CompanyID : %#" , CompanyID);
NSLog(#"VisitorName : %#" , VisitorName);
NSLog(#"OperatorName : %#" , OperatorName);
NSLog(#"countryCode: %#" , isocode);
NSLog(#"------------------------------------------------------------------------------");
}
Can some one help me to get the values out of this string ?
You are getting Array of Dictionary in response, but your response is in string so you convert it to NSArray using NSJSONSerialization like this way for that convert your response string to NSData and after that use that data with JSONObjectWithData: to get array from it.
NSString *jsonString = #"[{\"VisitorID\":\"2864983a-e26b-441a-aedf-84e2a1770b8e\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kanasalingam\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]},{\"VisitorID\":\"133bc108-b3bf-468a-9397-e1b0dba449db\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kumar\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]}]";
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *e;
NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&e];
Now loop through the array and access the each dictionary from it.
for (NSDictionary *dic in jsonArray) {
NSLog(#"%#",[dic objectForKey:#"VisitorID"]);
... and so on.
}
First you need to parse your string.
NSString *aString = #"[{\"VisitorID\":\"2864983a-e26b-441a-aedf-84e2a1770b8e\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kanasalingam\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]},{\"VisitorID\":\"133bc108-b3bf-468a-9397-e1b0dba449db\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kumar\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]}]";
NSData *data = [aString dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(#"%#",[[json objectAtIndex:0] objectForKey:#"VisitorID"]);
So you have JSON string and array of 2 objects. So write following code
This will convert JSON string to Array
NSData *myJSONData = [YOUR_JSON_STRING dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSMutableArray *arrayResponse = [NSJSONSerialization JSONObjectWithData:myJSONData options:NSJSONReadingMutableContainers error:&error];
Now use for loop and print data as
for (int i = 0; i < arrayResponse.count; i++) {
NSDictionary *dictionaryTemp = [arrayResponse objectAtIndex:i];
NSLog(#"VisitorID : %#",[dictionaryTemp valueForKey:#"VisitorID"]);
NSLog(#"ProfileID : %#",[dictionaryTemp valueForKey:#"ProfileID"]);
NSLog(#"CompanyID : %#",[dictionaryTemp valueForKey:#"CompanyID"]);
NSLog(#"VisitorName : %#",[dictionaryTemp valueForKey:#"VisitorName"]);
}
Now there are good chances that you will get NULL for some keys and it can cause in crash. So avoid those crash by using Null validations.

Setting data in correct JSON format using Array and Dictionary

Below is the model for which I have to set the data. I am using array and dictionary to achieve this, Here is the code which I tried. But its giving me the output which is invalid JSON.
One more thing I want to ask is why the log of an array starts and ends with small braces?
Any help would be much appreciated.
Code:
NSDictionary *paramDic = [NSDictionary dictionaryWithObjectsAndKeys:
parameterName,#"parameterName",
parameterType, #"parameterType",
[NSNumber numberWithBool:parameterSorting],#"parameterSorting",[NSNumber numberWithBool:parameterSorting],
#"parameterOrdering",
nil];
NSMutableArray *paramArray = [NSMutableArray arrayWithObject:paramDic];
NSDictionary *paramData = #{#"rqBody":#{#"catalogName":#"",#"userId":#"", #"parameter":paramArray, #"catalogMode":#""}};
NSData *postData = [NSKeyedArchiver archivedDataWithRootObject:paramData];`
Output:
{"rqBody":{"catalogName":"abcd","userId":"65265hgshg76","parameter":"(
{
parameterName = anandShankar;
parameterOrdering = 1;
parameterSorting = 1;
parameterType = Text;
}
)","catalogMode":"xxxxxx"}}
Desired Output:
{"rqBody":{"catalogName":"abcd","userId":"65265hgshg76","parameter":[{
"parameterName" : "anandShankar",
"parameterOrdering" : 1,
"parameterSorting" : 1,
"parameterType" : "Text"
}],"catalogMode":"xxxxxx"}}
There is nothing wrong in it. in console or log round braces () indicates array. if it is showing round braces then it is array. you will never het [] square braces in console or log.
Update :
NSData *data = [NSJSONSerialization dataWithJSONObject:paramData options:kNilOptions error:nil];
and then send this data to server. it will in your desired json fromat
hope this will help :)
Try this code :
NSDictionary *paramDic = [NSDictionary dictionaryWithObjectsAndKeys:
#"Object1",#"parameterName",
#"Object2", #"parameterType",
#'Object3',#"parameterSorting",#"Object4",
#"parameterOrdering",
nil];
NSMutableArray *paramArray = [NSMutableArray arrayWithObject:paramDic];
NSDictionary *paramData = #{#"rqBody":#{#"catalogName":#"",#"userId":#"", #"parameter":paramArray, #"catalogMode":#""}};
Add this lines :
NSError * err;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:paramData options:0 error:&err];
NSString * myString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(#"%#", myString); // it will print valid json
JSON
{
"rqBody":{
"catalogName":"",
"parameter":[
{
"parameterOrdering":"Object4",
"parameterName":"Object1",
"parameterType":"Object2",
"parameterSorting":51
}
],
"userId":"",
"catalogMode":""
}
}

'NSInvalidArgumentException', reason: '-[__NSCFString allKeys]: unrecognized selector sent to instance 0x7ae2f750'

responce stored in dictionary :
dict_Profile=[response objectForKey:#"unknown_object"];
after that am doing like this
lbl_HeadName.text=[NSString stringWithFormat:#"%#",[dict_Profile objectForKey:#"FirstName"]];
this data getting from server
getUserProfileResponse
{
"status_code" = 200;
"unknown_object" = "{
ID:90,FirstName:Dr.Alekhya,LastName:Kasoju,GivenName:Alekhya Kumar,DOB:1993-07-15T00:00:00,_DcotorAction:edit,
Languages:[44,45,46],
Designations[5102],PersonalEmailID:alekhya.k#inativetech.com,
PersonalContactNo:7675879511,Medical_Council_ID:MED003,
ProfilePhoto:Doctor_9015763545-Attractive-young-Indian-Female-Doctor-with-notepad-isolated-on-white--Stock-Photo.jpg,PracticeStartedOn:2013,LanguagesList:[{Key:44,Value:Telugu},{Key:45,Value:English},{Key:46,Value:Hindi},{Key:47,Value:Tamil},{Key:138,Value:Urdhu},{Key:139,Value:oriya},{Key:140,Value:Bengali},{Key:141,Value:kanada},{Key:142,Value:Marati},{Key:144,Value:Kashmiri},{Key:198,Value:card},{Key:4304,Value:malayalam},{Key:4310,Value:Sanksrit},{Key:4311,Value:German},{Key:4350,Value:Japanies},{Key:5275,Value:PGDMC},{Key:5518,Value:physicians}],DesignationsList:[{Key:5100,Value:Allergist or Immunologist},{Key:5101,Value:Anesthesiologist },{Key:5102,Value:Cardiologist},{Key:5103,Value:Dermatologist },{Key:5104,Value:Gastroenterologist},{Key:5105,Value:Hematologist/Oncologist },{Key:5106,Value:Internal Medicine Physician },{Key:5108,Value:Nephrologist\U00c2\U00a0 },{Key:5109,Value:Neurologist\U00c2\U00a0 },{Key:5110,Value:Neurosurgeon },{Key:5111,Value:Obstetrician },{Key:5112,Value:Gynecologist},{Key:5113,Value:Nurse-Midwifery },{Key:5114,Value:Occupational Medicine Physician},{Key:5115,Value:Ophthalmologist },{Key:5116,Value:Oral and Maxillofacial Surgeon\U00c2\U00a0 },{Key:5117,Value:Orthopaedic Surgeon },{Key:5118,Value:Otolaryngologist\U00c2\U00a0(Head and Neck Surgeon)\U00c2\U00a0 },{Key:5119,Value:Pathologist\U00c2\U00a0 },{Key:5120,Value:Pediatrician },{Key:5121,Value:Plastic Surgeon\U00c2\U00a0 },{Key:5122,Value:Podiatrist\U00c2\U00a0 },{Key:5123,Value:Psychiatrist },{Key:5124,Value:Pulmonary Medicine Physician },{Key:5125,Value:Radiation Onconlogist\U00c2\U00a0 },{Key:5126,Value:Diagnostic Radiologist },{Key:5127,Value:Rheumatologist\U00c2\U00a0 },{Key:5128,Value:Urologist },{Key:5129,Value:Orthopedist},{Key:5216,Value:Ayurveda},{Key:5519,Value:physicians},{Key:5897,Value:Ayurved},{Key:5898,Value:Ayurvedic},{Key:7442,Value:Homeopathy Doctor},{Key:7921,Value:Homeopath},{Key:8770,Value:Gynecologist/Obstetrician},{Key:8771,Value:MBBS,DGO},{Key:8774,Value:Spine Surgeon},{Key:8775,Value:MS (Ortho), FNB - Spine Surgery},{Key:8779,Value:Gastroentrology Surgeon},{Key:8780,Value:General Surgeon},{Key:8781,Value:Dentist},{Key:8783,Value:ENT},{Key:8784,Value:Radiology},{Key:8785,Value:General Surgery},{Key:8786,Value:Homeopathic},{Key:8787,Value:Trichologist},{Key:8788,Value:Diabetologist},{Key:8791,Value:Laboratory Medicine},{Key:8801,Value:Hematologist}],YearsList:[{Key:0,Value:-- Select Year--},{Key:2016,Value:2016},{Key:2015,Value:2015},{Key:2014,Value:2014},{Key:2013,Value:2013},{Key:2012,Value:2012},{Key:2011,Value:2011},{Key:2010,Value:2010},{Key:2009,Value:2009},{Key:2008,Value:2008},{Key:2007,Value:2007},{Key:2006,Value:2006},{Key:2005,Value:2005},{Key:2004,Value:2004},{Key:2003,Value:2003},{Key:2002,Value:2002},{Key:2001,Value:2001},{Key:2000,Value:2000},{Key:1999,Value:1999},{Key:1998,Value:1998},{Key:1997,Value:1997},{Key:1996,Value:1996},{Key:1995,Value:1995},{Key:1994,Value:1994},{Key:1993,Value:1993},{Key:1992,Value:1992},{Key:1991,Value:1991},{Key:1990,Value:1990},{Key:1989,Value:1989},{Key:1988,Value:1988},{Key:1987,Value:1987},{Key:1986,Value:1986},{Key:1985,Value:1985},{Key:1984,Value:1984},{Key:1983,Value:1983},{Key:1982,Value:1982},{Key:1981,Value:1981},{Key:1980,Value:1980},{Key:1979,Value:1979},{Key:1978,Value:1978},{Key:1977,Value:1977},{Key:1976,Value:1976},{Key:1975,Value:1975},{Key:1974,Value:1974},{Key:1973,Value:1973},{Key:1972,Value:1972},{Key:1971,Value:1971},{Key:1970,Value:1970},{Key:1969,Value:1969},{Key:1968,Value:1968},{Key:1967,Value:1967},{Key:1966,Value:1966},{Key:1965,Value:1965},{Key:1964,Value:1964},{Key:1963,Value:1963},{Key:1962,Value:1962},{Key:1961,Value:1961},{Key:1960,Value:1960},{Key:1959,Value:1959},{Key:1958,Value:1958},{Key:1957,Value:1957},{Key:1956,Value:1956},{Key:1955,Value:1955},{Key:1954,Value:1954},{Key:1953,Value:1953},{Key:1952,Value:1952},{Key:1951,Value:1951},{Key:1950,Value:1950},{Key:1949,Value:1949},{Key:1948,Value:1948},{Key:1947,Value:1947},{Key:1946,Value:1946},{Key:1945,Value:1945},{Key:1944,Value:1944},{Key:1943,Value:1943},{Key:1942,Value:1942},{Key:1941,Value:1941},{Key:1940,Value:1940},{Key:1939,Value:1939},{Key:1938,Value:1938},{Key:1937,Value:1937},{Key:1936,Value:1936},{Key:1935,Value:1935},{Key:1934,Value:1934},{Key:1933,Value:1933},{Key:1932,Value:1932},{Key:1931,Value:1931},{Key:1930,Value:1930},{Key:1929,Value:1929},{Key:1928,Value:1928},{Key:1927,Value:1927},{Key:1926,Value:1926},{Key:1925,Value:1925},{Key:1924,Value:1924},{Key:1923,Value:1923},{Key:1922,Value:1922},{Key:1921,Value:1921},{Key:1920,Value:1920},{Key:1919,Value:1919},{Key:1918,Value:1918},{Key:1917,Value:1917},{Key:1916,Value:1916}]}";
}
as you see, the unknown_object in your response is just a string, not a json object,so it will be translated to a NSString * object, but not a dictionary.
if you want unknown_object to be a dictionary, you can adjust your response like following:
getUserProfileResponse
{
"status_code" = 200;
"unknown_object" = {
"ID" : 90,
"FirstName" : "Dr.Alekhya",
......
}
}
or
make your unknown_object to a valid json string,then transfer it back to a dictionary, like this:
NSData *data = [#"{\"id\" : 1}" dataUsingEncoding:NSUTF8StringEncoding];
[NSJSONSerialization JSONObjectWithData:data
options:NSJSONWritingPrettyPrinted
error:nil];
allKeys is a property of Dictionary to which provides array of Keys in that dictionary.
Looks like you are calling allKeys on NSString object, Because of that you are getting this error.
Convert your String object to valid Dictionary. Try below
NSString *jsonString = "your string"
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
Hope it helps.
The response that you are getting is not actually a dictionary, so you need to convert NSSting to NSDictionary.
NSString *response = #"{ \"status_code\" : 200, \"unknown_object\" : { \"ID\" : \"90\", \"FirstName\" : \"Dr.Alekhya\"} }";
NSError *error;
NSData *data = [response dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict_Profile = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
NSLog(#"res = %#", dict_Profile);
//get data from dictionary
NSString *strName = [NSString stringWithFormat:#"%#",[[dict_Profile objectForKey:#"unknown_object"] valueForKey:#"FirstName"]];
NSLog(#"FirstName = %#", strName);
it may help you:
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:[response dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];

Converting NSString to JSON with NSJSONSerialization is not working

I have this function:
- (void)checkLogin:(NSString *)pLogin andPassword:(NSString*) pPassword {
//Create the data object.
NSMutableDictionary *tLoginAndPasword = [NSMutableDictionary dictionaryWithObjectsAndKeys:pLogin,#"Login",pPassword,#"Password", nil];
NSMutableDictionary *tData = [NSMutableDictionary dictionaryWithObjectsAndKeys:[_Util serializeDictionary:tLoginAndPasword],#"Data", nil];
//Call the login method.
NSData *tResponse = [_Util getLogin:tData];
if (tResponse != Nil) {
_oLabelErrorLogin.hidden = YES;
[_Util setUser:pLogin andPassword:pPassword];
NSMutableDictionary *tJSONResponse =[NSJSONSerialization JSONObjectWithData:tResponse options:kNilOptions error:nil];
NSString *tPayload = [tJSONResponse objectForKey:#"Payload"];
if([[tJSONResponse objectForKey:#"StatusCode"] isEqual: #"424"]) {
//Set global values.
NSData *tPayloadData = [tPayload dataUsingEncoding:NSUTF8StringEncoding];
if ([NSJSONSerialization isValidJSONObject:tPayloadData]) {
_Payload = [NSJSONSerialization JSONObjectWithData:tPayloadData options:kNilOptions error:nil];
_RowCount = _Payload.count;
} else {
NSLog(#"JSON Wrong String %#",tPayload);
}
} else if([[tJSONResponse objectForKey:#"StatusCode"] isEqual: #"200"]){
_Payload = Nil;
}
} else {
//Set global values.
_Payload = Nil;
_oLabelErrorLogin.hidden = NO;
//Clear login data.
_oLogin.text = #"";
_oPassword.text = #"";
[_Util setUser:#"" andPassword:#""];
}
}
The JSON response looks like this:
{
"Payload": "{\"UserName\":\"Marco Uzcátegui\",\"Clients\":[{\"UserProfileId\":4,\"ProfileName\":\"Platform Administrator\",\"ClientName\":\"Smart Hotel Platform\",\"InSession\":true},{\"UserProfileId\":5,\"ProfileName\":\"Administrator\",\"ClientName\":\"La Moncloa de San Lázaro\",\"InSession\":false},{\"UserProfileId\":6,\"ProfileName\":\"Administrator\",\"ClientName\":\"Jardín Tecina\",\"InSession\":false}]}",
"StatusCode": "424",
"StatusDescription": null
}
As you can see, I have a escaped string inside "Payload" that is a correct JSON, so I want to generate another NSMutableDictionary with that string, so I'm doing this:
NSData *tPayloadData = [tPayload dataUsingEncoding:NSUTF8StringEncoding];
if ([NSJSONSerialization isValidJSONObject:tPayloadData]) {
_Payload = [NSJSONSerialization JSONObjectWithData:tPayloadData options:kNilOptions error:nil];
_RowCount = _Payload.count;
} else {
NSLog(#"JSON Wrong String %#",tPayload);
}
So I'm creating an NSData from the NSString and asking if is valid, it always returns false.
I have tried to replace the "\" from the string and is not working.
[tPayload stringByReplacingOccurrencesOfString:#"\\\"" withString:#""]
I have tried to create a NSMutableDictionary with the string, but the result is not a dictionary.
NSMutableDictionary *tPayload = [tJSONResponse objectForKey:#"Payload"];
I'm kind of lost here.
Any help will be appreciated.
Regards.
The issue is this line
[NSJSONSerialization isValidJSONObject:tPayloadData]
From the documentation of isValidJSONObject
Returns a Boolean value that indicates whether a given object can be
converted to JSON data.
given object means an NSArray or NSDictionary but not NSData
Remove that check and implement the error parameter in JSONObjectWithDataoptions:error:
The method NSJSONSerialization.isValidJSONObject: checks if an object (e.g. a NSDictonary or NSArray instance) can be converted to JSON. It doesn't check if a NSData instance can be converted from JSON. For NSData, it will always return false.
So just call NSJSONSerialization.JSONObjectWithData:options: and check the result instead.

iOS autocomplete from JSON instead of array

I want to make an autocomplete with a tableView, for that I have this function :
-(AutocompletionTableView *)autoCompleter
{
if (!_autoCompleter)
{
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithCapacity:2];
[options setValue:[NSNumber numberWithBool:YES] forKey:ACOCaseSensitive];
[options setValue:nil forKey:ACOUseSourceFont];
_autoCompleter = [[AutocompletionTableView alloc] initWithTextField:self.textField inViewController:self withOptions:options];
_autoCompleter.autoCompleteDelegate = self;
_autoCompleter.suggestionsDictionary = [NSArray arrayWithObjects:#"hostel",#"caret",#"carrot",#"house",#"horse", nil];
}
return _autoCompleter;
}
The Problem :
Instead of autocompleting from an Array, I want to autocomplete from a remote JSON file.
Any idea on I how I can do such thing ? A code snippet will be very helpful, as I am a newbie in iOS development.
After making a request to the server using NSURLConnection, you should receive an NSData containing the following data:
["hostel","caret","carrot","house","horse"]
This NSData is something like this:
NSString* data = #"[\"hostel\",\"caret\",\"carrot\",\"house\",\"horse\"]";
NSData* dataReceived = [data dataUsingEncoding:NSUTF8StringEncoding];
So, to convert it into an array, you can call NSJSONSerialization, like this:
NSError *jsonError = nil;
NSArray *responseDictionary = [NSJSONSerialization JSONObjectWithData:dataReceived options:0 error:&jsonError];
if(jsonError == nil)
{
_autoCompleter.suggestionsDictionary = responseArray;
}

Resources