| 65 | |
| 66 | |
| 67 | bool JSONConverter::encodeJSON(slice json) { |
| 68 | _input = json; |
| 69 | _errorMessage.clear(); |
| 70 | _errorCode = NoError; |
| 71 | _jsonError = JSONSL_ERROR_SUCCESS; |
| 72 | _errorPos = 0; |
| 73 | |
| 74 | _jsn->data = this; |
| 75 | _jsn->action_callback_PUSH = writePushCallback; |
| 76 | _jsn->action_callback_POP = writePopCallback; |
| 77 | _jsn->error_callback = errorCallback; |
| 78 | jsonsl_enable_all_callbacks(_jsn); |
| 79 | |
| 80 | jsonsl_feed(_jsn, (char*)json.buf, json.size); |
| 81 | if (_jsn->level > 0 && !_jsonError) { |
| 82 | // Input is valid JSON so far, but truncated: |
| 83 | _jsonError = kErrTruncatedJSON; |
| 84 | _errorCode = JSONError; |
| 85 | _errorPos = json.size; |
| 86 | } |
| 87 | jsonsl_reset(_jsn); |
| 88 | return (_jsonError == JSONSL_ERROR_SUCCESS); |
| 89 | } |
| 90 | |
| 91 | /*static*/ alloc_slice JSONConverter::convertJSON(slice json, SharedKeys *sk) { |
| 92 | Encoder enc; |