在PHP中解析Javascript(而不是JSON) [英] Parsing Javascript (not JSON) in PHP

查看:369
本文介绍了在PHP中解析Javascript(而不是JSON)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含javascript对象序列化的php字符串:

I have a php string containing the serialization of a javascript object :

$string = '{fu:"bar",baz:["bat"]}';

当然,实际的字符串要复杂得多,但仍然是格式良好的javascript。这不是标准的JSON,因此json_decode失败。你知道任何解析这个字符串并返回php关联数组的php库吗?

The actual string is far more complicated, of course, but still well-formed javascript. This is not standard JSON, so json_decode fails. Do you know any php library that would parse this string and return a php associative array ?

推荐答案

Pear Services_JSON 将解析该字符串(测试版本1.31)。但鉴于这是一个JSON解析器并且这不是有效的JSON,您无法保证将来的版本仍然有效。

Pear Services_JSON will parse that string (tested version 1.31). But given that that is a JSON parser and that this isn't valid JSON you have no guarantee that future versions will still work.

这篇关于在PHP中解析Javascript(而不是JSON)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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