简体   繁体   中英

JSON Response In Javascript

I am using DEEP AI for WhatsAsena (World's first UserBot for WhatsApp) And ı'm not good at json Sooo here is my code:

Asena.addCommand({pattern: 'faceai ?(.*)', fromMe: true, deleteCommand: false, dontAddCommandList: true}, (async (message, match) => {
    if (match[1] === '') return await message.sendMessage('Need İmage URL');

    var resp = await deepai.callStandardApi("facial-recognition", {
        image: `${match[1]}`,

    });

    await message.reply(`Output: ${resp}`);

}));

When I am using local terminal the output is:

{
    'id': 'aa4905c4-be34-491b-ac6c-029388ab137b',
    'output': {
        'expressions': [ {
            'emotion': 'fear',
            'bounding_box': [111, 171, 269, 269],
            'confidence': '0.91'
        } ]
    }
}

I m using ${resp} but ı want to scrape [{'emotions': 'fear'

I want to like this;

Output: fear, happy.. etc

Only emotions . How can I do that?

Disclaimer: I am unfamiliar with DeepAI.

const resp = await deepai.callStandardApi("facial-recognition", { image: `${match[1]}` } );

let emotion = null;
if( ( resp.expressions || [] ).length === 1 ) {
    const expr = resp.expressions[0];
    if( typeof expr.emotion === 'string' ) {
        emotion = expr.emotion;
    }
}

if( emotion ) {
    await message.reply( `Output: ${emotion}` );
}
else {
    await message.reply( "Error: No 'emotion' in response." );
}

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