forked from Telodendria/Cytoplasm
Merge pull request 'Add a function to decode a JSON value directly.' (#60) from lda/Cytoplasm:raw-types into master
Reviewed-on: Telodendria/Cytoplasm#60
This commit is contained in:
commit
b4841fffaa
2 changed files with 25 additions and 0 deletions
|
@ -297,6 +297,12 @@ extern size_t JsonEncode(HashMap *, Stream *, int);
|
||||||
*/
|
*/
|
||||||
extern HashMap * JsonDecode(Stream *);
|
extern HashMap * JsonDecode(Stream *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a JSON value from thr current input strram and parse it
|
||||||
|
* into a JsonValue.
|
||||||
|
*/
|
||||||
|
extern JsonValue * JsonValueDecode(Stream *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenience function that allows the caller to retrieve and
|
* A convenience function that allows the caller to retrieve and
|
||||||
* arbitrarily deep keys within a JSON object. It takes a root JSON
|
* arbitrarily deep keys within a JSON object. It takes a root JSON
|
||||||
|
|
19
src/Json.c
19
src/Json.c
|
@ -1348,6 +1348,25 @@ JsonDecode(Stream * stream)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
JsonValue *
|
||||||
|
JsonValueDecode(Stream *stream)
|
||||||
|
{
|
||||||
|
JsonValue *result;
|
||||||
|
JsonParserState state;
|
||||||
|
|
||||||
|
state.stream = stream;
|
||||||
|
state.token = NULL;
|
||||||
|
|
||||||
|
JsonTokenSeek(&state);
|
||||||
|
result = JsonDecodeValue(&state);
|
||||||
|
|
||||||
|
if (state.token)
|
||||||
|
{
|
||||||
|
Free(state.token);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
JsonValue *
|
JsonValue *
|
||||||
JsonGet(HashMap * json, size_t nArgs,...)
|
JsonGet(HashMap * json, size_t nArgs,...)
|
||||||
|
|
Loading…
Reference in a new issue