mcorest_api_json_numeric_as_double
此函数将 JSON 数值转换为双精度浮点数。
如果 str 不包含数值,则返回错误代码。
MCO_RET mcorest_api_json_numeric_as_i64(
const char *str,
mco_int8 *val
);参数
str
const char
一个数字型的 JSON 值。
val
double
一个双精度浮点数的地址。
返回
MCO_S_OK
成功。
MCO_E_REST_ *
任何一种网络服务错误码。
示例
char buf[32];
mcorest_api_json_read_ctx_t jctx;
MCOREST_API_JSON_TKN_TYPE tkn_type;
...
if (MCO_S_OK == mcorest_api_json_next_token(&jctx, MCOREST_API_JSON_TKN_NUMBER, &tkn_type))
{
if (MCO_S_OK == mcorest_api_json_read_numeric(&jctx, buf, sizeof(buf)))
{
if (!mcorest_api_json_numeric_is_integer(buf))
{
double val;
mcorest_api_json_numeric_as_double(buf, &val); /* 将数值转换为双精度浮点数 */
}
}
}文件
- 头文件:
mcorestapi.h - 源文件:
jsonrd.c - 库:
libmcorest.a
