title: Error: call of overloaded 'stoi(nlohmann::basic_json<>::value_type&)' is ambiguous
body: <p>I'm using the Json for modern C++ project <a href="https://github.com/nlohmann/json" rel="nofollow noreferrer">here</a>. I met with the following problem. The <code>obj_json</code> is a json object and I want to get the value of <code>obj_json["key"][0][1]</code>, which shall be an integer value. Therefore I wrote:</p>
  
  <pre><code>int id;
  id = obj_json["key"][0][1];
  </code></pre>
  
  <p>I met with the error saying:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::domain_error'
    what():  type must be number, but is string
  </code></pre>
  
  <p>So I change the code to:</p>
  
  <pre><code>int id;
  id = std::stoi(obj_json["key"][0][1]);
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>error: call of overloaded 'stoi(nlohmann::basic_json&lt;&gt;::value_type&amp;)' is ambiguous
  In file included from /home/mypath/gcc-5.4.0/include/c++/5.4.0/string:52:0,
               from /home/mypath/gcc-5.4.0/include/c++/5.4.0/stdexcept:39,
               from /home/mypath/gcc-5.4.0/include/c++/5.4.0/array:38,
               from ../json-develop/src/json.hpp:33,
               from libnba.cpp:1:
  /home/mypath/gcc-5.4.0/include/c++/5.4.0/bits/basic_string.h:5258:3: note: candidate: int std::__cxx11::stoi(const string&amp;, std::size_t*, int)
     stoi(const string&amp; __str, size_t* __idx = 0, int __base = 10)
     ^
  /home/mypath/gcc-5.4.0/include/c++/5.4.0/bits/basic_string.h:5361:3: note: candidate: int std::__cxx11::stoi(const wstring&amp;, std::size_t*, int)
     stoi(const wstring&amp; __str, size_t* __idx = 0, int __base = 10)
  </code></pre>
  
  <p>I'm confused with this. As shown in the first error message, the <code>obj_json["key"][0][1]</code> is a <code>string</code>. But in the second error message, why does the error happens?
  I also print out the type of the object, using the following code:</p>
  
  <pre><code>cout &lt;&lt; typeid(obj_json["key"][0][1]).name() &lt;&lt; endl;
  </code></pre>
  
  <p>The type printed is </p>
  
  <pre><code>N8nlohmann10basic_jsonISt3mapSt6vectorNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEblmdSaEE
  </code></pre>
  
  <p>I'm totally confused...
  How to solve this?
  Thank you for helping me!</p>