I need to form PUT request like this:
First example created on Java (android):
public JSONObject putGameData(String answer_id) {
JSONObject jsonObject = new JSONObject();
if(myAnswersArray.contains(new String(answer_id))){
for(int i = 0; i < myAnswersArray.size(); i++)
if(answer_id.equals(myAnswersArray.get(i)))
myAnswersArray.remove(i);
} else {
myAnswersArray.add(answer_id);
}
JSONArray jsonArray = new JSONArray(myAnswersArray);
try {
jsonObject.put("answer_id", jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject;
}
PARAMETERS: {"answer_id":["a104fccc555a60ea8e437d8b7f11dd12","ad4277811a26ebea5d72d09a164531ee","5a1cc90dc9b51d6f8793759cab11728f"],"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJzdWIiOiIx}
On iOS app I send parameters like this and it's not correct. My parameters are with \n and other whitespaces...
PARAMETERS: {"{\"answer_id\":":{"\"20052e3c88ef5c16d9ae0ac0d86ffbca\",\"2600c200e39815352ec1c7d602d67d25\"":""},"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJzdWIiOiIxMzUiLCJpc3MiOiJodHRwOlwv"}
I did:
NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:multipleAnswersArray options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSASCIIStringEncoding];
[post setObject:multipleAnswersArray forKey:@"answer_id"];
and then perform put data:
NSData *postData = [NSJSONSerialization dataWithJSONObject:post options:0 error:&error];
How to make correct format like on first example?