douye2110 2011-02-27 15:05
浏览 55
已采纳

将字符串解析为数组{{navigation({“class”:“navigation”,“id”:“navigation”})}}第2部分

Let simplify the question:

All I need is to explode() string by a comma between brackets. The problem is that elements selected by comma can have a comma in itself, thus simple exploding won't work. I am not asking how to decode JSON.

The number of arguments, their type will always be different, e.g.

('foo')
('bar', NULL)
({"JSON": "data"}, 'test')

Assuming that I have this part of the code:

({"class": "navigation", "id": "navigation"}, NULL, 'bar' /* [..] */)

Can anyone suggest a regex (or alternative method) to get all the comma separated entries (as string)? The problem is that variables can contain commas in itself. Thus, I assume this requires recursion.

Expected result would be an array containing following entries:

{"class": "navigation", "id": "navigation"}
NULL
'bar'
  • 写回答

5条回答 默认 最新

  • douman6245 2011-02-27 16:15
    关注

    After many hours of work, I have come across that PHP will fail to parse JSON string containing NULL (uppercase null). That was what caused the following code not to work. However, simply replacing NULL to null solved the problem.

    var_dump(json_decode('[{"class": "navigation", "id": "navigation"}, NULL, "bar"]')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊