2
將我的NSString處理成有效的JSON字符串時遇到一些麻煩。正確格式化NSString for JSON
NSString *version = @"1.1";
NSString *callMethod = @"auth.login";
NSString *paramsConfig = [NSString stringWithFormat:@"{\"email\":\"%@\",\"password\":\"%@\"}", usernameString, passwordString];
int queryId = arc4random()% 10000000;
NSDictionary *userData = [NSDictionary dictionaryWithObjectsAndKeys:version, @"version", callMethod, @"method", [NSNumber numberWithInt:queryId], @"id", paramsConfig, @"params", nil];
NSString* jsonString = [userData JSONRepresentation];
預期JSON字符串:
{"version":"1.1","params":"{"email":"s","password":"s"}","id":12345678,"method":"auth.login"}
實際JSON字符串:
{"version":"1.1","params":"{\"email\":\"s\",\"password\":\"s\"}","id":12345678,"method":"auth.login"}
不能確定我要去哪裏錯了。有什麼想法嗎?
感謝
山姆
現貨! 非常感謝你的魅力。 – Sam 2010-05-14 13:24:22