简体   繁体   中英

How to read a key value from JSON string?

I want to read a value from a JSON String using JSONCPP. Here is my JSON

{
    "action": "SCAN",
    "table": "Log",
    "rowLimit": "1000",
    "colFam": [
        "i"
    ],
    "filter": [
        {
            "op": "prefix",
            "cf_qn": "ROWKEYS",
            "val": "1#1404906729"
        }
    ],
    "rows": [
        {
            "rowNum": "1",
            "rowKey": "1#1404906729#",
            "cells": [
                {
                    "qf": "i:appName",
                    "val": "TestApp"
                },
                {
                    "qf": "i:chBy",
                    "val": "Test Logger"
                },
                {
                    "qf": "i:comp",
                    "val": "TestMessageFromSDK"
                },
                {
                    "qf": "i:crDt",
                    "val": "07/12/2014 12:03:53"
                },
                {
                    "qf": "i:devId",
                    "val": "DevID1234"
                },
                {
                    "qf": "i:emailHash",
                    "val": "xyz@mail.com"
                },
                {
                    "qf": "i:epoch",
                    "val": "1404906729"
                },
                {
                    "qf": "i:groupId",
                    "val": "99999999"
                },
                {
                    "qf": "i:mcName",
                    "val": "Test-adev-w8"
                },
                {
                    "qf": "i:profId",
                    "val": "88888888"
                },
                {
                    "qf": "i:prty",
                    "val": "1"
                },
                {
                    "qf": "i:ts",
                    "val": "2014-07-12 11:52:01"
                }
            ]
        }
    ],
    "stts": "Filters Set"
}

I want to get "val": "TestMessageFromSDK" .

How to do it ?

You can write code to extract this value yourself but why reinvent the wheel? There are a lot of JSON parsing libraries available for C++. Take a look at this link and see if it helps you.

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