Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include "jsmn.h"
- int main() {
- std::string json = "{\n"
- " \"id\": 1,\n"
- " \"username\": \"test\",\n"
- " \"password\": \"password\",\n"
- " \"role\": \"USER\"\n"
- " }";
- jsmn_parser parser;
- jsmntok_t tokens[20];
- jsmn_init(&parser);
- int result = jsmn_parse(&parser, json.c_str(), json.length(), tokens, 20);
- std::cout << "start: " << tokens[1].start << " end: " << tokens[1].end << std::endl;
- std::string id_label = json.substr(tokens[1].start, (tokens[1].end - tokens[1].start));
- std::cout << id_label << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement