Example #1
0
 RetType as() const
 {
     if (boost::optional<RetType> v = cjson_cast<RetType>(json_)) {
         return *v;
     }
     else {
         throw json_parse_error("JSON parse error");
     }
 }
Example #2
0
    inline array parse(const ndt::type &ret_tp, const char *begin, const char *end)
    {
      skip_whitespace(begin, end);

      ndt::type dst_tp2 = ret_tp;
      char *args_data[2] = {reinterpret_cast<char *>(&begin), reinterpret_cast<char *>(&end)};
      nd::array ret =
          dynamic_parse->call(dst_tp2, 0, nullptr, nullptr, args_data, 0, nullptr, std::map<std::string, ndt::type>());

      skip_whitespace(begin, end);
      if (begin != end) {
        throw json_parse_error(begin, "unexpected trailing JSON text", ret_tp);
      }

      return ret;
    }