Closed varmint2all closed 9 years ago
It's an annoying issue that I haven't found an idea how to fix yet.
I have the same kind of problem, the compiler finds the [0] indexing to be ambiguous. I fixed it like this : cout << v4["array"][(size_t)0] << endl; // Compiles with a cast cout << v4["array"][1] << endl; // compiles fine
Bug at line 26?
Lines 27 and 28 work if 26 commented out! ===============temp2.json====================== {"name" : "tommy", "entries" : [ "I am a string", 234, { "deep":777, "name":null } ], "age" : 23, "salary" : 25.10, "male" : true } ============== error ==================== c:\toolbox\cpp\src\json\src\main.cpp(26) : error C2593: 'operator [' is ambiguous c:\toolbox\cpp\src\json\src\Value.h(241): could be 'JsonBox::Value &Json Box::Value::operator ' c:\toolbox\cpp\src\json\src\Value.h(228): or 'JsonBox::Value &Json Box::Value::operator [](const char *)' while trying to match the argument list '(JsonBox::Object::mapped_type,int)' ============== code ======================= 01 //...Input from a file 02 JsonBox::Value v2; 03 v2.loadFromFile("temp2.json"); 04 std::cout << v2 << std::endl; 05 std::cout << "Type=" << v2.getType() << std::endl; 06 if (v2.isObject()) std::cout << "Object" << std::endl; 07 08 // Print out from Value 09 std::cout << "===================================\n"; 10 JsonBox::Object o2 = v2.getObject(); 11 std::cout << "Size=" << o2.size() << std::endl; 12 std::cout << "Name=" << o2["name"] << std::endl; 13 std::cout << "Deep=" << o2["entries"] << std::endl; 14 15 for (JsonBox::Object::const_iterator i = o2.begin(); i != o2.end(); i++) 16 { 17 std::string key; 18 JsonBox::Value v3; 19 key = i->first; 20 v3 = i->second; 21 std::cout << "ITER: " << key << ":" << i->second << 22 ":" << v3.getType() << std::endl; 23 //std::cout << typeid(i->second).name() << std::endl; 24 } 25 26 std::cout << "Deep[0]=" << o2["entries"][0] << std::endl; 27 std::cout << "Deep[1]=" << o2["entries"][1] << std::endl; 28 std::cout << "Deep[2]=" << o2["entries"][2] << std::endl; 29 std::cout << "...End test" << std::endl; 30 }