ios - Retrieving multiple users from Parse via REST API and using only one AFNetworking request -


i need retrieve multiple users parse.com, via rest api, , using afnetworking. need retrieve these users using 1 single api call.

the following code able fetch 1 user. notice including 1 objectid because fetching 1 user. need modify code can call multiple objectid's , result, retrieve multiple users:

//setup request manager afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager];  [manager.requestserializer setvalue:applicationid forhttpheaderfield:@"x-parse-application-id"]; [manager.requestserializer setvalue:apikey forhttpheaderfield:@"x-parse-rest-api-key"]; [manager.requestserializer setvalue:@"application/json" forhttpheaderfield:@"content-type"];  nsdictionary *query = @{@"objectid":@"cbfg5dfjy7"}; nserror *error; nsdata *jsondata = [nsjsonserialization datawithjsonobject:query                                                    options:0                                                      error:&error]; if (!jsondata) {     nslog(@"error: %@", [error localizeddescription]); } nsstring *datequerystring = [[nsstring alloc] initwithdata:jsondata                                                   encoding:nsutf8stringencoding]; nsdictionary *parameters = @{@"where": datequerystring};  //perform request [manager get:[nsstring stringwithformat:@"%@users", baseurlstring] parameters:parameters      success:^(afhttprequestoperation *operation, id responseobject) {           // handle success          completion(nil, self.mentors, nil);       } failure:^(afhttprequestoperation *operation, nserror *error) {          // handle failure          completion(nil, nil, error);      }]; 

in parse.com rest api documentation, says can perform compound or query achieve this, , lists following in request curl example:

--data-urlencode 'where={"$or":[{"wins":{"$gt":150}},{"wins":{"$lt":5}}]}' \ 

unfortunately, not know how translate objective-c. here same example in python if helps:

params = urllib.urlencode({"where":json.dumps({        "$or": [          {            "wins": {              "$gt": 150            }          },          {            "wins": {              "$lt": 5            }          }        ]      })}) 

i need include multiple objectid's in afnetworking call, , tell parse.com i'll accept results objectid, or objectid, etc. parse.com return of users me.

you have single dictionary query convert json

nsdictionary *query = @{@"objectid":@"cbfg5dfjy7"}; 

the or example show dictionary single key, value array of dictionaries current query.

@{@"$or":@[ @{@"objectid":@""} , @{@"objectid":@""} ]} 

once have built structure convert json , add request are.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -