0

プログラムからデータを操作する作業を行っていて、このデータ形式に出会いましたが、解析方法がわかりません。

response="0",num=3,list=[
{type="url1",url="http://www.xxx1.com"},
{type="url2",url="http://www.xxx2.com"},
{type="url3",url="http://www.xxx3.com"}
],type="LIST", id=1

誰か提案はありますか?

ありがとう!

4

2 に答える 2

0

この形式が何かはわかりませんが、JSON に非常に近いものです。

必要なのは、余分な中かっこに置き換えkey="key":ラップするだけで有効な JSON になるため、任意の JSON ライブラリを使用して解析できます。

次の Perl コードを使用して解析できます。

use JSON::XS;

my $input = qq{
    response="0",num=3,list=[
    {type="url1",url="http://www.xxx1.com"},
    {type="url2",url="http://www.xxx2.com"},
    {type="url3",url="http://www.xxx3.com"}
    ],type="LIST", id=1
};
my $str = "{" . $input . "}";
$str =~ s/(\w+)=/"$1":/g; # replace key= with "key": (fragile!)
my $json = decode_json($str);
# at this point, $json is object containing all fields you need.
# ...
于 2013-06-09T08:26:09.897 に答える