open-source-parsers / jsoncpp

A C++ library for interacting with JSON.
Other
8.06k stars 2.63k forks source link

How to set both key and value pair as variable #1511

Open hf81-ble opened 11 months ago

hf81-ble commented 11 months ago

Describe the bug I want to write a generic storage handler into an json file. Key and value are variables

void setSetting ( CString key, Integer value)
{
Json::Value data;
data[key] = value;
///write json
}

Result in VS2022 Compiler: Severity Code Description Project File Line Suppression State Error C2678 binary '[': no operator found which takes a left-hand operand of type 'Json::Value' (or there is no acceptable conversion) Editor ConfigJson.cpp 61

To Reproduce Steps to reproduce the behavior:

  1. Use a variable as key instead of a static String

Expected behavior should write the key/pair pair

Desktop (please complete the following information):