-1

I have below key pair to be pass in my JSON input working fine with Postman REST client extension but on hitting with iOS webservice it gives "error parameter missing".

msg={
    "Data": {
            "ID": "1",
            "password": "password123",
            "type": "good",
            "name": "testuser"
     },
     "apicode": "1234",
     "key": "12133"
}

Here is my JSON dictionary I have created, please check any error in it ?

NSError *error;
    NSDictionary * Datadic = [NSDictionary dictionaryWithObjectsAndKeys:
                                                ID, @"ID",
                                                password, @"password",
                                                type, @"type",
                                                name, @"name",
                                                nil];


    NSDictionary *json_Dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                                      Datadic, @"Data",
                                                      apicode, @"apicode",
                                                      key, @"key",
                                                      nil];




    NSDictionary *jsonmsgDDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                           json_Dictionary, @"msg",
                                           nil];

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject: jsonmsgDDictionary options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSLog(@"jsonData as string:\n%@", jsonString);

On creating URL using above jsonstring

NSString *urlstring=[NSString stringWithFormat:@"http://%@:%@/signUp?msg-%@",self.input_hostaddress,self.input_portNo,jsonstring];

Then

NSURL *url = [NSURL URLWithString:urlstring];

/// this line url = nil why ?

9to5ios
  • 5,319
  • 2
  • 37
  • 65

1 Answers1

1

Json should start with array or dictionary. It will not start with string. In your JSON remove msg=. Then it will work.

Try this

{
"Data": {
"ID": "1",
"password": "password123",
"type": "good",
"name": "testuser"
},
"apicode": "1234",
"key": "12133"
}

If msg key is mandatory then add either array or dictionary to your existing JSON.

Sample:

{  
   "msg":{  
      "Data":{  
         "ID":"1",
         "password":"password123",
         "type":"good",
         "name":"testuser"
      },
      "apicode":"1234",
      "key":"12133"
   }
}

For more info: https://stackoverflow.com/a/5034547/3051458

Community
  • 1
  • 1
Ramesh_T
  • 1,251
  • 8
  • 19
  • msg= is manadatory , if i remove it from POSTMAN it also give parameter missing error – 9to5ios Jan 25 '16 at 11:28
  • Sorry I am not aware of POSTMAN. Try to use https://jsonformatter.curiousconcept.com/ or JSON Editor(Chrome Extention). – Ramesh_T Jan 25 '16 at 11:40
  • @iphonemaclover : if you paste your entire string "msg=..." in jsonlint.com it will tell you what Ramesh has told you. This is not valid JSON. – YvesLeBorg Jan 25 '16 at 11:40