0

I am using iPhone JSON Web Service based app.I need to pass input parameter as an array to a JSON web Service, how can I do this?

Array Contains 12 elements. Here am providing sample service... input parametes for this service: dev_id = 1; dev_name= josh and array items (projectslist,companyidentifier)

http://www.jyoshna.com/api/developer.php?dev_id=1&dev_name=josh&(Here i need to pass the array elements)

can any help us how to pass array as a input parameter to the json service?

1

3 Answers 3

1

First you have to convert array as JSON string

NSString *requestString=[jsonParser stringWithObject:array];

convert string to data

NSData *data=[requestString dataUsingEncoding:NSUTF8StringEncoding];

set that data as request Body

[request setHTTPBody:data];
Sign up to request clarification or add additional context in comments.

Comments

0

You have to serialize the array and pass as an argument. Dont forget to unserialize in server side

Comments

0

you will need to create an NSMutabelDictionary of your array then JSON encode it, you can then send the resulting string you your webservice however you choose. I tend to build a POST request and send it that way

NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];
NSMutableDictionary *tagData = [[NSMutableDictionary alloc] init];
for(int i = 0; i < array.count; i++)
{
    NSString *keyString = [NSString stringWithFormat:@"key%i", i];
    [tagData setObject:[array objectAtIndex:i] forKey:keyString];
}

[jsonDict setObject:tagData forKey:@"entries"];

NSData* data = [NSJSONSerialization dataWithJSONObject:jsonDict
                                               options:NSJSONWritingPrettyPrinted error:&error];

NSString* aStr;
aStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

It is the sgtring aStr that you need to send

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.