将查询字符串解析为结构化NSDictionary [英] Parse Query String into a Structured NSDictionary

查看:149
本文介绍了将查询字符串解析为结构化NSDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询字符串: a = 1& b = 2& c [1] = 3& c [2] = 4 等...

I have a query string: a=1&b=2&c[1]=3&c[2]=4 etc…

我想要一个NSDictionary,其中 a => 1 b => 2,c =>。 [3,4] 。请注意,c的值是一个数组。它也应该能够处理像 c [1] [2] = 5 这样的数组来创建数组 c => [[5]]

I want a NSDictionary where a => 1, b => 2, c => [3,4]. Notice that that the value for c is an array. It should also be able to handle something like c[1][2]=5 to make an array of arrays c => [[5]].

当然,我可以通过拆分& = ,但是其他情况如数组和数组数组。我想从POST请求queryString中获取 结构化 NSDictionary,并且如果已经存在,则不想重写轮。

Of course I can do it myself by splitting on the & and =, but what about other cases such as arrays and arrays of arrays. I want a structured NSDictionary from a POST request queryString and do not want to rewrite the wheel if this already exists.

有没有任何类/方法,通过苹果或第三方,将解析查询字符串到一个结构化的NSDictionary?

Are there any class/method, through Apple or 3rd party, that will parse a query string into a structured NSDictionary?

推荐答案

Google Toolbox for Mac 包含 GTMNSDictionaryURLArgumentsAdditions code> category NSDictionary 这可以做你想要的。

The Google Toolbox for Mac contains a GTMNSDictionaryURLArgumentsAdditions category on NSDictionary which may do what you want.

如果你可以控制查询字符串(在客户端),你可以发送一个编码plist,可以直接解码为 NSDictionary

If you have control over the query string (on the client side), you could send an encoded plist which can be decoded directly into an NSDictionary.

这篇关于将查询字符串解析为结构化NSDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆