这个对象符号格式是什么?(What is this object notation format?)

编程入门 行业动态 更新时间:2024-10-28 20:31:36
这个对象符号格式是什么?(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=1

Does 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. # ...

更多推荐

本文发布于:2023-07-30 23:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   对象   格式   format   notation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!