プログラムからデータを操作する作業を行っていて、このデータ形式に出会いましたが、解析方法がわかりません。
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
誰か提案はありますか?
ありがとう!
この形式が何かはわかりませんが、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.
# ...