Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

取某一个value 怎么用呢? #2

Closed
rjzou opened this issue Mar 21, 2022 · 4 comments
Closed

取某一个value 怎么用呢? #2

rjzou opened this issue Mar 21, 2022 · 4 comments

Comments

@rjzou
Copy link

rjzou commented Mar 21, 2022

json_value_t *json_value_parse(const char *doc);
这里的返回 json_value_t 不是整个json吗?
const char *json_value_string(const json_value_t *val);
再把整个json_value_t 作为参数 去取value 吗?

@Barenboim
Copy link
Owner

我在这个issue里有介绍接口的用法:
sogou/workflow#815
一个json文档,就是对应到一个json value。value有多种类型。你说的string是value的一种,可以通过json_value_type()接口得到value类型。

@rjzou
Copy link
Author

rjzou commented Mar 21, 2022

{
"userName ": "111111",
"pwd ": "123456 "
}

用哪个方法get("userName") 的值。

@Barenboim
Copy link
Owner

Barenboim commented Mar 21, 2022

{
    const char *doc = " { ... } ";
    json_value_t *val = json_value_parse(doc);

    if (val)
    {
        const json_object_t *obj = json_value_object(val);
        if (obj) 
        {
            const json_value_t *v = json_object_find("userName", obj);
            if (v)
            {
                const char *str = json_value_string(v);  // "111111"
                ...
            }
            ... 
        }
        json_value_destroy(val);
    }

}

@rjzou
Copy link
Author

rjzou commented Mar 21, 2022

谢谢

@rjzou rjzou closed this as completed Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants