What is the issue you have?
I have a JSON string like this
{
"message": {
"chat": {
"id": -1001128970273,
"title": "Private Cloud",
"type": "supergroup"
}
}
}
Then, I want to get the ["message"]["chat"]["id"], but cannot get the correct value.
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
Example code
#include <cstdio>
#include "include/json.hpp"
using json = nlohmann::json;
int main() {
json me = json::parse("{\"message\":{\"chat\":{\"id\":-1001128970273,\"title\":\"Private Cloud\",\"type\":\"supergroup\"}}}");
int me_int = me["message"]["chat"].value("id", 0);
long me_long = me["message"]["chat"].value("id", 0);
long long me_long_long = me["message"]["chat"].value("id", 0);
printf("Int: %d\n", me_int);
printf("Long: %ld\n", me_long);
printf("Long long: %lld\n", me_long_long);
}
What is the actual behavior?
Program output:
ammarfaizi2@CraynerCenter:~/project/now/bot-s6$ g++ test.cpp -o test
ammarfaizi2@CraynerCenter:~/project/now/bot-s6$ ./test
Int: -401590305
Long: -401590305
Long long: -401590305
What is the expected behavior?
Expected result
How can I get the -1001128970273 value?
Which compiler and operating system are you using? Is it a supported compiler?
Compiler Detail:
ammarfaizi2@CraynerCenter:~/project/now/bot-s6/build$ g++ --version
g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
OS Detail:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Linux Lite 4.0"
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Did you use a released version of the library or the version from the develop branch?
What is the issue you have?
I have a JSON string like this
{ "message": { "chat": { "id": -1001128970273, "title": "Private Cloud", "type": "supergroup" } } }Then, I want to get the
["message"]["chat"]["id"], but cannot get the correct value.Please describe the steps to reproduce the issue. Can you provide a small but working code example?
Example code
What is the actual behavior?
Program output:
What is the expected behavior?
Expected result
How can I get the
-1001128970273value?Which compiler and operating system are you using? Is it a supported compiler?
Compiler Detail:
OS Detail:
Did you use a released version of the library or the version from the
developbranch?I used the released version (downloaded from: https://github.com/nlohmann/json/releases/download/v3.6.1/json.hpp)
I will check it up soon.