简体   繁体   中英

how can i handle my json elements

Here is my json file

{
        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

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? i am new to react.js and es6,javascript.so i have no idea to display each property. 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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