本文介绍了Objective C + Reskit - 如何使用键包装我的字典以避免格式化问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试用一个密钥封装我的HTTP POST请求。换句话说,我想转一下:I'm trying to wrap my HTTP POST request with a key. In other words, I want to turn this:{"category_id"=>"1", "food_name_token"=>"Pizza", "id"=>"1"}进入:{"dish" => { "category_id"=>"1", "food_name_token"=>"Pizza", "id"=>"1" }} I tried using the 'rootKeyPath' method in RestKit:serializationMapping.rootKeyPath = @"dish"; 但是,这给了我这种奇怪格式的字符串:But that gave me this weirdly formatted string :{"dish"=> "{ \n \"category_id\" = 1; \n \"food_name_token\" = Pizza; \n id = 1; \n}"}它使用等号和分号而不是箭头和逗号,并添加所有这些换行符和转义反斜杠。It uses equal signs and semicolons instead of arrows and commas, and adds in all these linebreaks and escape backslashes.任何想法为什么?还有任何关于我能做什么的建议?Any idea why? And any suggestions on what I can do instead?我正在使用Rails后端P.S. I'm using a Rails backend推荐答案我发现与Restkit我可以用括号包装属性:I found out with Restkit I can wrap attributes using brackets: [dishMapping mayKeyPath:@"dish[food_name_token]" toAttribute:@"placeToken"];这样可以让我输出一个没有奇怪格式的正常输出。And this gives me a normal output without the weird formatting. 这篇关于Objective C + Reskit - 如何使用键包装我的字典以避免格式化问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 14:27