查询字符串中的复杂对象

Complex object in a query string

如何在查询字符串中使用这种结构?

"properties": {
        "list": [
            {
                "label": "bye",
                "value": "world"
            },
            {
                "label": "hello",
                "value": "mars"
            }
        ]
    }

我已经用 properties[][list][label]=bye&properties[][list][value]=world&properties[0][label]=hello&properties[0][value]=marsproperties[][list][label]=bye&properties[][list][value]=world&properties[][list][label]=hello&properties[][list][value]=mars 试过了,其中 none 成功了。我用 http_build_query.

在 php 中构建了它们

我需要在查询字符串中包含此结构,因为我必须将数据连同其他带有 POST 的内容一起发送到 PHP 站点。

我在您的查询字符串中看到两个错误:

  • properties是一个对象,所以不需要使用[]来添加元素。
  • list是一个数组,所以查询字符串中必须使用数字索引。

正确的查询字符串是:

?properties[list][0][label]=bye
&properties[list][0][value]=world
&properties[list][1][label]=hello
&properties[list][1][value]=mars

(为了便于阅读,multi-lined)