Skip to content

cannot parse from string? #1349

@addriumruss

Description

@addriumruss

here is my code:

#include <stdio.h>
#include<stdlib.h>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main(int argc, char **argv){

// create object from string literal
// parse explicitly
std::string text = "{ \"happy\": true, \"pi\": 3.141 }";
auto j = json::parse(text);

std::string str = j.dump();

printf("j=%s \n", str);

printf("happy=%d, pi=%f \n", j["happy"], j["pi"]);

return 0;
}

this is build:
g++ -Wall -std=c++14 -I./json/include -L./json/lib test4.cpp -o t4

and result:
./t4
j=
happy=25431392, pi=0.000000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions