GmResultDigest::GmResultDigest(const Json::Value &jsonTypeValuePair) { fIsValid = false; if (!jsonTypeValuePair.isArray()) { gm_fprintf(stderr, "found non-array json value when parsing GmResultDigest: %s\n", jsonTypeValuePair.toStyledString().c_str()); DEBUGFAIL_SEE_STDERR; } else if (2 != jsonTypeValuePair.size()) { gm_fprintf(stderr, "found json array with wrong size when parsing GmResultDigest: %s\n", jsonTypeValuePair.toStyledString().c_str()); DEBUGFAIL_SEE_STDERR; } else { // TODO(epoger): The current implementation assumes that the // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5 Json::Value jsonHashValue = jsonTypeValuePair[1]; if (!jsonHashValue.isIntegral()) { gm_fprintf(stderr, "found non-integer jsonHashValue when parsing GmResultDigest: %s\n", jsonTypeValuePair.toStyledString().c_str()); DEBUGFAIL_SEE_STDERR; } else { fHashDigest = jsonHashValue.asUInt64(); fIsValid = true; } } }
Json::Value Connection::process_result(const Json::Value& value) { if(value.isObject()) { Json::Value id = value["id"]; if(!id.isIntegral() or id.asInt() != 0) { std::stringstream error; error << value.toStyledString() << " is no id=0"; throw ConnectionError(error.str()); } Json::Value jsonrpc = value["jsonrpc"]; if(!jsonrpc.isString()) { std::stringstream error; error << value.toStyledString() << " has no string member: jsonrpc"; throw ConnectionError(error.str()); } Json::Value result = value["result"]; if(!result.isObject()) { std::stringstream error; error << value.toStyledString() << " has no object member: result"; throw ConnectionError(error.str()); } return result; } else { std::stringstream error; error << value.toStyledString() << " is no json object"; throw ConnectionError(error.str()); } }
bool Deserialize ( const Json::Value& json_val, json_lib::uint64& obj_val ) { if ( json_val.isIntegral () ) { obj_val = json_val.asUInt64 (); return true; } return false; }
void LuaModule::pushKey(const Json::Value &key, lua_State * stack) { if (key.isString()) { lua_pushstring(stack, key.asString().c_str()); } else if (key.isIntegral()) { throw std::runtime_error("Integer keys must not be pushed. " "Use lua_rawseti();"); } else { throw std::runtime_error("Key is not string nor integer"); } }
unsigned long JsonUtils::asUnsignedLong(const Json::Value &value, long unsigned int defaultValue) { long unsigned int returned = defaultValue; if(value.isString()) returned = Ogre::StringConverter::parseUnsignedLong(value.asString(), defaultValue); if(value.isIntegral()) returned = value.asUInt64(); return returned; }
int JsonUtils::asInt(const Json::Value &value, int defaultValue) { int returned = defaultValue; if(value.isString()) returned = Ogre::StringConverter::parseInt(value.asString(), defaultValue); if(value.isIntegral()) returned = value.asInt(); return returned; }
bool Deserialize ( const Json::Value& json_val, unsigned int& obj_val ) { /** * Warning: the default type may be int, even you Serialize a uint value */ if ( json_val.isIntegral () ) { obj_val = json_val.asUInt (); return true; } return false; }
/***************以下函数用于读取json静态数据***************/ unsigned int to_uint(const Json::Value& val) { if ( val.isIntegral() ) return val.asUInt(); if ( val.isDouble() ) return (unsigned int)val.asDouble(); if ( val.isString() ) return strtoul(val.asCString(), NULL, 0 ); return 0; }
void ValueTest::checkIs( const Json::Value &value, const IsCheck &check ) { JSONTEST_ASSERT_EQUAL( check.isObject_, value.isObject() ); JSONTEST_ASSERT_EQUAL( check.isArray_, value.isArray() ); JSONTEST_ASSERT_EQUAL( check.isBool_, value.isBool() ); JSONTEST_ASSERT_EQUAL( check.isDouble_, value.isDouble() ); JSONTEST_ASSERT_EQUAL( check.isInt_, value.isInt() ); JSONTEST_ASSERT_EQUAL( check.isUInt_, value.isUInt() ); JSONTEST_ASSERT_EQUAL( check.isIntegral_, value.isIntegral() ); JSONTEST_ASSERT_EQUAL( check.isNumeric_, value.isNumeric() ); JSONTEST_ASSERT_EQUAL( check.isString_, value.isString() ); JSONTEST_ASSERT_EQUAL( check.isNull_, value.isNull() ); }
void LuaModule::pushValue(const Json::Value &val, lua_State * stack) { if (val.isIntegral()) { lua_pushinteger(stack, val.asInt()); } else if (val.isDouble()) { lua_pushnumber(stack, val.asDouble()); } else if (val.isBool()) { lua_pushboolean(stack, val.asBool()); } else if (val.isString()) { lua_pushstring(stack, val.asString().c_str()); } else if (val.isNull()) { //lua_pushstring(stack, val.asString().c_str()); lua_pushnil(stack); } else { lua_pop(stack, 1); std::stringstream ss; ss << val.type(); std::string typeNum; ss >> typeNum; throw std::runtime_error("Value type error: value of type " + typeNum); } }