Revision 2016.05.03
Fork of MbedJSONValue by
Diff: MbedJSONValue.cpp
- Revision:
- 7:174bc7a49aa2
- Parent:
- 6:f8bec9cada34
--- a/MbedJSONValue.cpp Tue Apr 05 11:37:53 2016 +0000 +++ b/MbedJSONValue.cpp Tue May 03 02:14:45 2016 +0000 @@ -107,15 +107,21 @@ void MbedJSONValue::serialize(std::back_insert_iterator<std::string> oi) { +#ifdef DEBUG_MJSON printf("SP:%X _type=%d, index=%d\r\n",__current_sp(),_type, index_token); +#endif switch (_type) { case TypeString: +#ifdef DEBUG_MJSON printf("typestring\r\n"); +#endif serialize_str(*_value.asString, oi); break; case TypeArray: { +#ifdef DEBUG_MJSON printf("typearray\r\n"); +#endif *oi++ = '['; for (int i = 0; i < index_array; i++) { if (i) @@ -126,13 +132,19 @@ break; } case TypeObject: { +#ifdef DEBUG_MJSON printf("typeObject\r\n"); +#endif *oi++ = '{'; for (int i = 0; i < index_token; i++) { +#ifdef DEBUG_MJSON printf("i=%d ",i); +#endif if (i) *oi++ = ','; +#ifdef DEBUG_MJSON printf("token_name[%d]=%s\r\n",i,token_name[i]->c_str()); +#endif serialize_str(*(token_name[i]), oi); *oi++ = ':'; (*(token[i])).serialize(oi); @@ -141,7 +153,9 @@ break; } default: +#ifdef DEBUG_MJSON printf("default\r\n"); +#endif copy(to_str(), oi); break; } @@ -176,14 +190,14 @@ MbedJSONValue& MbedJSONValue::operator[](std::string k) { _type = TypeObject; for (int i = 0; i < index_token; i++) { -#ifdef DEBUG +#ifdef DEBUG_MJSON printf("k: %s\r\n", k.c_str()); printf("str: %s\r\n", token_name[i]->c_str()); #endif //existing token if (!strcmp(k.c_str(), token_name[i]->c_str())) { -#ifdef DEBUG +#ifdef DEBUG_MJSON printf("token found: %d\r\n", i); #endif return *(token[i]); @@ -195,10 +209,14 @@ //non existing token //token_name[index_token] = new std::string(k); token_name.push_back(new std::string(k)); +#ifdef DEBUG_MJSON printf("New token_name[%d]=%X, %s\r\n", index_token, token_name[index_token], token_name[index_token]->c_str()); +#endif //token[index_token] = new MbedJSONValue(); token.push_back(new MbedJSONValue()); +#ifdef DEBUG_MJSON printf("New token[%d]=%X, %d\r\n", index_token, token[index_token], token[index_token]->getType()); +#endif index_token++; return *(token[index_token - 1]); } @@ -206,7 +224,7 @@ MbedJSONValue& MbedJSONValue::operator[](std::string k) const { for (int i = 0; i < index_token; i++) { -#ifdef DEBUG +#ifdef DEBUG_MJSON printf("k: %s\r\n", k.c_str()); //printf("str: %s\r\n", token_name[i]->c_str()); #endif @@ -214,7 +232,7 @@ printf(" comp "); printf("[%s]\r\n", token_name[i]->c_str()); if (!strcmp(k.c_str(), token_name[i]->c_str())) { -#ifdef DEBUG +#ifdef DEBUG_MJSON printf("token found: %d\r\n", i); #endif return *(token[i]);