diff --git a/ext/vjson/json.cpp b/ext/vjson/json.cpp index 6015b7c76e..bdd7bb1db4 100644 --- a/ext/vjson/json.cpp +++ b/ext/vjson/json.cpp @@ -33,6 +33,11 @@ int json_value::numSiblings() const { const json_value *json_value::get(const char *child_name) const { if (!this) { FLOG("Cannot get from null node"); + return 0; + } + if (!child_name) { + FLOG("JSON: Cannot get from null child name"); + return 0; } const json_value *c = first_child; while (c) { @@ -52,7 +57,7 @@ const json_value *json_value::get(const char *child_name, json_type type) const return 0; } -const char *json_value::getString(const char *child_name) const { +const char *json_value::getStringOrDie(const char *child_name) const { const json_value *val = get(child_name, JSON_STRING); if (val) return val->string_value; diff --git a/ext/vjson/json.h b/ext/vjson/json.h index 997f46b9aa..792ab1cba4 100644 --- a/ext/vjson/json.h +++ b/ext/vjson/json.h @@ -7,8 +7,7 @@ #include "block_allocator.h" #include "file/vfs.h" -enum json_type -{ +enum json_type { JSON_NULL, JSON_OBJECT, JSON_ARRAY, @@ -18,8 +17,7 @@ enum json_type JSON_BOOL, }; -struct json_value -{ +struct json_value { json_value() {} json_value *parent; @@ -47,7 +45,7 @@ struct json_value const json_value *getDict(const char *child_name) const { return get(child_name, JSON_OBJECT); } - const char *getString(const char *child_name) const; + const char *getStringOrDie(const char *child_name) const; const char *getString(const char *child_name, const char *default_value) const; bool getStringVector(std::vector *vec) const; float getFloat(const char *child_name) const; @@ -69,7 +67,6 @@ private: json_value *json_parse(char *source, char **error_pos, char **error_desc, int *error_line, block_allocator *allocator); void json_print(json_value *value, int ident = 0); - // Easy-wrapper class JsonReader { public: @@ -114,10 +111,3 @@ private: DISALLOW_COPY_AND_ASSIGN(JsonReader); }; - -// TODO: Make this a push/pop interface similar to JsonWriter. Maybe -// we can get to the point where reading and writing is near identical or the same code. -class JsonCursor { -public: - -};