这个对象符号格式是什么?(What is this object notation format?)
我正在努力操作程序中的数据,我遇到了这种数据格式,但我无法弄清楚如何解析它。
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有没有人有什么建议?
谢谢!
I'm working on manipulating data from a program, and I came across this data format, but I can't figure out how to parse it.
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=1Does anyone have any suggestions?
Thanks!
最满意答案
我不知道这种格式是什么,但它非常接近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. # ...I don't know what this format is, but it is very close to JSON.
All you need is to replace key= with "key": and wrap around extra braces to make it valid JSON, so then you can use any JSON library to parse it.
You can parse it using this Perl code:
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. # ...更多推荐
发布评论