简体   繁体   English

我如何处理我的json元素

[英]how can i handle my json elements

Here is my json file 这是我的json文件

{
        id: '81224112234234222223422229',
        type: 'message',
        message: 'vacation',
        attachments: [
            {
                type: 'template',
                elements: [
                    {
                        id: '123123123123123',
                        title: 'job',
                        text: 'job',
                        properties: {
                            code: 'IO002',
                            value: 'messenger/IO001,messenger2(IO)/IO002,messenger3(IO)/IO003'
                        }
                    },
                    {
                        id: '123123123123123',
                        title: 'Date',
                        text: 'date',
                        properties: {
                            code: '2017-11-09~2017-11-09',
                            value: '2017-11-09~2017-11-09'
                        }
                    },
                    {
                        id: '123123123123123',
                        title: 'Sequence',
                        text: 'sequence',
                        properties: {
                            code: '1',
                            value: '1process/1,2process/1,3process/1'
                        }
                    }
                ]
            }
        ],
        module: 'temp'
}

i am using react.js and i want to extract all properties 我正在使用react.js,我想提取所有属性

result 结果

job code: I0002
job value:messenger/IO001,messenger2(IO)/IO002,messenger3(IO)/IO003

date code:2017-11-09~2017-11-09
date value:2017-11-09~2017-11-09

sequence code:1
sequence value:1process/1,2process/1,3process/1

i tried to execute like this 我试图这样执行

const job=elements.filter(x=>x.text==='job');
const date=elements.filter(x=>x.text==='date');
const sequence=elements.filter(x=>x.text==='sequence');

is it proper way to use filter or another way to extract data from json file? 是否使用过滤器或其他方法从json文件提取数据的正确方法? i am new to react.js and es6,javascript.so i have no idea to display each property. 我是React.js和es6,javascript.so的新手,所以我不知道显示每个属性。 how can i solve my problem? 我该如何解决我的问题? pz give me a tip.i want to extract properties 请给我一个提示。我想提取属性

You can use 您可以使用

var yourobject=JSON.parse(jsondata);
const job=yourobject.job;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM