samedi 17 avril 2021

Why is decltype for nlohmann json object different?

How do I extract information of underlying datatype from nlohmann object? Since the values are stored as primitive datatypes in the json why don't it give the output like a and b below?

I see typedef as below for ordered json.

nlohmann::basic_json<nlohmann::ordered_map,std::vector, std::string, bool, std::int64_t, std::uint64_t, double>;

So it's clear the type of values it's storing(?).

int main()
{
  json js;
  js["key1"] = 1L;
  js["key2"]  = 0.111f;

  auto a = 1L;
  auto b = 0.111f;


  decltype(js["key1"]) x = js["key1"];
  decltype(js["key2"]) y = js["key2"];

  cout<<typeid(a).name()<<endl;
  cout<<typeid(b).name()<<endl;
  cout<<typeid(x).name()<<endl;
  cout<<typeid(y).name()<<endl;

}

Output:

l
f
N8nlohmann10basic_jsonINS_11ordered_mapESt6vectorNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEblmdSaNS_14adl_serializerES2_IhSaIhEEEE
N8nlohmann10basic_jsonINS_11ordered_mapESt6vectorNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEblmdSaNS_14adl_serializerES2_IhSaIhEEEE

Aucun commentaire:

Enregistrer un commentaire