php nsdata,转换NSArray-> JSON-> NSData-> PHP服务器-> JSON表示

我正在使用以下命令将NSDictionaries数组转换为JSON数据…

创建我的数据…

NSMutableArray *arrayOfDicts = [[NSMutableArray alloc] init];

for (int i = 0; i < 2; i++) {

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:

@"MySong", @"title",

@"MyArtist", @"artist",

nil];

[arrayOfDicts addObject:dict];

}

NSArray *info = [NSArray arrayWithArray:arrayOfDicts];

NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info

options:NSJSONWritingPrettyPrinted error:&error];

然后像这样发送…

NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com/index.php"];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[request setPostValue:jsonData forKey:@"songs"];

[request setDelegate:self];

request.tag = TAG_LOAD_SONGS;

[request startAsynchronous];

这会将NSData发送到我的服务器,但是我该如何在php中使用它…如果我从我的服务器上打印它,它实际上只是一堆随机数,并且我尝试使用json_encode,但是我认为那并不意味着原始数据…

任何帮助将是巨大的!

编辑:这是PHP的响应…

echo $_POST['songs'];

<5b0a2020 7b0a2020 20202274 69746c65 22203a20 224d7953 6f6e6722 2c0a2020 20202261 72746973 7422203a 20224d79 41727469 7374220a 20207d2c 0a20207b 0a202020 20227469 746c6522 203a2022 4d79536f 6e67222c 0a202020 20226172 74697374 22203a20 224d7941 72746973 74220a20 207d0a5d>

这是对Xcode中NSLoging的响应…

NSLog(@"Info: %@", info);

信息:({艺术家= MyArtist;标题= MySong;},{艺术家= MyArtist;标题= MySong;})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值