From 0b485e95fa7c963403485948fe519b0ab9f32e06 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 11 Jan 2014 22:39:28 +0100 Subject: [PATCH] Don't add null terminator to each token. --- JsonObjectBase.cpp | 3 +++ JsonParser.cpp | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/JsonObjectBase.cpp b/JsonObjectBase.cpp index 231cf205..345e2b67 100644 --- a/JsonObjectBase.cpp +++ b/JsonObjectBase.cpp @@ -23,5 +23,8 @@ char* JsonObjectBase::getTokenString(jsmntok_t* token) if (token->type != JSMN_PRIMITIVE && token->type != JSMN_STRING) return 0; + // add null terminator to the string + json[token->end] = 0; + return json + token->start; } \ No newline at end of file diff --git a/JsonParser.cpp b/JsonParser.cpp index 0c2b02bc..bb5da5c5 100644 --- a/JsonParser.cpp +++ b/JsonParser.cpp @@ -20,11 +20,5 @@ jsmntok_t* JsonParserBase::parse(char* jsonString) if (JSMN_SUCCESS != jsmn_parse(&parser, jsonString, tokens, maxTokenCount)) return 0; - // Add null termination to each token - for (int i = 1; i < parser.toknext; i++) - { - jsonString[tokens[i].end] = 0; - } - return tokens; } \ No newline at end of file