ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
3.04k stars 262 forks source link

How can I get the key in yyjson_mut_val ? #88

Closed zestzone007 closed 2 years ago

zestzone007 commented 2 years ago

Is your feature request related to a problem? Please describe. I can't find how to get the key of the yyjson_mut_val,is there any functions to get the key ?

Describe the solution you'd like can sombody add get key functions to yyjson lib?

Describe alternatives you've considered as we known,json is key/value based protocol, Get the key name is an very important function to json libs.

Additional context Add any other context or screenshots about the feature request here.

ibireme commented 2 years ago

JSON objects should not be used in this way. If it's really what you need, use an iterator to iterate over all key-value pairs to find the specified key: https://github.com/ibireme/yyjson/blob/ee9e6d5d3bde4a26b78e9cfd596dd28d231266fa/src/yyjson.h#L2803-L2808

See also: https://github.com/ibireme/yyjson/blob/master/doc/DataStructure.md#mutable-document

zestzone007 commented 2 years ago

JSON objects should not be used in this way. If it's really what you need, use an iterator to iterate over all key-value pairs to find the specified key:

https://github.com/ibireme/yyjson/blob/ee9e6d5d3bde4a26b78e9cfd596dd28d231266fa/src/yyjson.h#L2803-L2808

See also: https://github.com/ibireme/yyjson/blob/master/doc/DataStructure.md#mutable-document

this help me a lot,thanks.