使用PERL解析JSON [英] Parse JSON with PERL

查看:268
本文介绍了使用PERL解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用PERL解析JSON字符串.
我的JSON字符串;

I'd like to parse a JSON string with PERL.
My JSON string;

{"to_id": 0, "message": "This is a sample", "message_id": 1000, "from_id": 999}


如何解析JSON并返回所有对象和值.
样本输出;


How to parse the JSON and return all objects and values.
Sample output;

to_id: 0
message: This is a sample
message_id: 1000
from_id: 999


在单独的变量中没有XML输出以及对象和值

在此先感谢


No XML output and object and value in separate variables

Thanks in advance

推荐答案

使用 JSON 模块.这是一个使用方法的示例:

Use the JSON module. Here's an example of how to use it:

use strict;
use warnings;
use Data::Dumper;
use JSON;

my $str = q|{"to_id": 0, "message": "This is a sample", "message_id": 1000, "from_id": 999}|;

print Dumper from_json($str);

输出:

$VAR1 = {
          'from_id' => 999,
          'message_id' => 1000,
          'to_id' => 0,
          'message' => 'This is a sample'
        };

这篇关于使用PERL解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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