ios发布到php工作,但json_decode返回NULL

时间:2015-01-07 21:09:12

标签: php ios json

ios app从coredata中提取信息并通过POST将其与简单的变量(如用户ID)一起发送到Web服务(php)。

userid和看起来像这样的原始json一样精细

json string(607) "<5b7b226b 6579776f 72643122 3a226e61 76792073 65616c73 222c226e 616d6532 223a2262 6c6f7768 61726422 2c226e61 6d653122 3a226a6f 6520626c 6f77222c 22636974 79737461 7465223a 226e6170 6c65732c 20666c6f 72696461 222c226b 6579776f 72643222 3a227573 73206e65 77222c22 6b657977 6f726433 223a2272 6f746172 79227d2c 7b226b65 79776f72 6431223a 22636174 63686572 222c226e 616d6532 223a2254 6f6d6d79 222c226e 616d6531 223a2254 6f6d2054 68756d62 222c2263 69747973 74617465 223a2257 6573746d 696e7374 65722c20 4d617373 222c226b 6579776f 72643222 3a226669 7368696e 67222c22 6b657977 6f726433 223a2268 756e7469 6e67227d 5d>"

但是,当我使用json_decode时,它返回null。

我已经尝试过修剪,执行substr,3技巧,mb_convert_encoding($ jsoninfo,&#39; UTF-8&#39;,&#39; UTF-8&#39;);以及我在网上找到的其他一些修正案,但没有任何工作。

以下是用于发布的xcode

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonArray options:0 error:&error];
NSString *post = [NSString stringWithFormat:@"uuid=%@&json=%@", UUID, jsonData];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

//Read the post length

NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

//Make a new NSMutableURLRequest, and add the necessary URL, Headers and POST Body

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.website.com/mycode.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

我假设它是我在尚未弄清楚的解码问题,但是我在xcode中缺少其他任何东西吗?

0 个答案:

没有答案