open-source-parsers / open-source-parsers/jsoncpp

How to set both key and value pair as variable

Open
#1,511 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
C++
Stars
8.9k
Forks
2.7k
Avg merge
31m
Merged PRs (30d)
1

Description

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):

  • OS: Win10
  • Visual Studio 2022

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ConfigJson.cpp line 61 and inspect the Json::Value operator[] overloads used with the variable key and value types. Reproduce the C2678 error in Visual Studio 2022, then confirm that the generic storage handler compiles and writes the expected key/value pair to the JSON file.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.