当前位置: 首页>>代码示例>>C++>>正文


C++ parse_json函数代码示例

本文整理汇总了C++中parse_json函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_json函数的具体用法?C++ parse_json怎么用?C++ parse_json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_json函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse_json

bool parse_json(ConnectionInfo& info, const json& j) {
	try {
		GET_NODE_ENUM(j, "type", ConnectionType, info.Type);
		GET_NODE_ENUM(j, "channel", RC_CHANNEL, info.Channel);
		GET_NODE_STRING(j, "dev_sn", info.DevSN, RC_MAX_SN_LEN);

		bool ret = true;
		switch(info.Type) {
		case CT_SERIAL:
			ret = parse_json(info.Serial, j["info"]);
			break;
		case CT_TCPC:
			ret = parse_json(info.TCPClient, j["info"]);
			break;
		case CT_UDP:
			ret = parse_json(info.UDP, j["info"]);
			break;
		case CT_TCPS:
			ret = parse_json(info.TCPServer, j["info"]);
			break;
		case CT_PLUGIN:
			ret = parse_json(info.Plugin, j["info"]);
			break;
		case CT_TEST:
		default:
			break;
		}
		return ret;
	}
	catch (...) {
		return false;
	}
}
开发者ID:kooiot,项目名称:rdc,代码行数:33,代码来源:DataJson.cpp

示例2: parse_json

json_t *json_loads(const char *string, json_error_t *error)
{
    lex_t lex;
    json_t *result;

    string_data_t stream_data = {
        .data = string,
        .pos = 0
    };

    if(lex_init(&lex, string_get, string_eof, (void *)&stream_data))
        return NULL;

    result = parse_json(&lex, error);
    if(!result)
        goto out;

    lex_scan(&lex, error);
    if(lex.token != TOKEN_EOF) {
        error_set(error, &lex, "end of file expected");
        json_decref(result);
        result = NULL;
    }

out:
    lex_close(&lex);
    return result;
}

json_t *json_loadf(FILE *input, json_error_t *error)
{
    lex_t lex;
    json_t *result;

    if(lex_init(&lex, (get_func)fgetc, (eof_func)feof, input))
        return NULL;

    result = parse_json(&lex, error);
    if(!result)
        goto out;

    lex_scan(&lex, error);
    if(lex.token != TOKEN_EOF) {
        error_set(error, &lex, "end of file expected");
        json_decref(result);
        result = NULL;
    }

out:
    lex_close(&lex);
    return result;
}
开发者ID:dcollien,项目名称:Humperdink-C,代码行数:52,代码来源:load.c

示例3: test_request

static void
test_request(const char *json)
{
    jsmntok_t tokens[32];
    int parsed = parse_json(
        tokens, LGTD_ARRAY_SIZE(tokens), json, strlen(json)
    );

    bool ok;
    struct lgtd_jsonrpc_request req = TEST_REQUEST_INITIALIZER;
    struct lgtd_client client = {
        .io = NULL, .current_request = &req, .json = json
    };
    ok = lgtd_jsonrpc_check_and_extract_request(&req, tokens, parsed, json);
    if (!ok) {
        errx(1, "can't parse request");
    }

    lgtd_jsonrpc_check_and_call_set_light_from_hsbk(&client);

    if (set_light_called) {
        errx(1, "lgtd_proto_power_off was called");
    }

    reset_client_write_buf();
}
开发者ID:aoighost,项目名称:lightsd,代码行数:26,代码来源:test_jsonrpc_check_and_call_set_light_from_hsbk_invalid_params.c

示例4: parse_json

json_t *json_loads(const char *string, json_error_t *error)
{
    lex_t lex;
    json_t *result;

    string_data_t stream_data = {
        /*.data = */string,
        /*.pos = */0
    };

    if(lex_init(&lex, string_get, string_eof, (void *)&stream_data))
        return NULL;

    result = parse_json(&lex, error);
    if(!result)
        goto out;

    lex_scan(&lex, error);
    if(lex.token != TOKEN_EOF) {
        error_set(error, &lex, "end of file expected");
        json_decref(result);
        result = NULL;
    }

out:
    lex_close(&lex);
    return result;
}
开发者ID:pavlog,项目名称:cgminer,代码行数:28,代码来源:load.c

示例5: main

int main(int argc, char* argv[])
{
  char* buffer;
  size_t length, body_pos;
  struct artist_album_state state = {0};
  int i;

  setlocale(LC_ALL, "");

  install_sighandler();

  httpreq(&buffer, &length);

  body_pos = http_body_offset(buffer, length);

  LOG(LOG_OK, "New relases:");
  parse_json(buffer + body_pos, length - body_pos, (void*)&state, artist_album_cb);

  for (i = 0; i < state.result_index; i++) {
    printf("%d. %s\n", i, state.result[i]);
  }

  spotify_main_loop(argv[1], argv[2], spotify_callback);

  free(buffer);

  for (i = 0; i < state.result_index; i++) {
   free(state.result[i]);
  }

  return 0;
}
开发者ID:padenot,项目名称:Serendipite,代码行数:32,代码来源:main.c

示例6: benchmarkFile

void benchmarkFile(char *filename)
{
    clock_t begin, end;
    double time_spent;
    
    json_token *tokens = calloc(sizeof(json_token), 3000000);
    
    json_parser parser;
    json_parser_init(&parser);
    
    
    parser.tokens = tokens;
    parser.maxTokens = 3000000;
    
    
    parser_from_file(&parser, filename);
    
    
    
    
    begin = clock();
    
    /* parse the json document */
    parse_json(&parser, RFC4627);
    
    
    end = clock();
    time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    
    printResults(&parser, filename, time_spent);
    
    file_parser_free(&parser);
    
    free(tokens);
}
开发者ID:aderussell,项目名称:arsn_json_parser,代码行数:35,代码来源:main.c

示例7: jsonp_error_init

json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
{
    lex_t lex;
    const char *source;
    json_t *result;

    if(input == stdin)
        source = "<stdin>";
    else
        source = "<stream>";

    jsonp_error_init(error, source);

    if (input == NULL) {
        error_set(error, NULL, "wrong arguments");
        return NULL;
    }

    if(lex_init(&lex, (get_func)fgetc, input))
        return NULL;

    result = parse_json(&lex, flags, error);

    lex_close(&lex);
    return result;
}
开发者ID:cryptobiote,项目名称:jansson,代码行数:26,代码来源:load.c

示例8: do_notify

static void
do_notify(struct ovs_cmdl_context *ctx)
{
    struct jsonrpc_msg *msg;
    struct jsonrpc *rpc;
    struct json *params;
    struct stream *stream;
    const char *method;
    char *string;
    int error;

    method = ctx->argv[2];
    params = parse_json(ctx->argv[3]);
    msg = jsonrpc_create_notify(method, params);
    string = jsonrpc_msg_is_valid(msg);
    if (string) {
        ovs_fatal(0, "not a JSON RPC-valid notification: %s", string);
    }

    error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream,
                              DSCP_DEFAULT), &stream);
    if (error) {
        ovs_fatal(error, "could not open \"%s\"", ctx->argv[1]);
    }
    rpc = jsonrpc_open(stream);

    error = jsonrpc_send_block(rpc, msg);
    if (error) {
        ovs_fatal(error, "could not send notification");
    }
    jsonrpc_close(rpc);
}
开发者ID:AlexanderChou,项目名称:ovs,代码行数:32,代码来源:test-jsonrpc.c

示例9: main

int main(int argc, char **argv)
{
    if(argc < 3) {
        fprintf(stderr, "%s out.db file1.json file2.json ... fileN.json\n", 
                argv[0]);
        return 0;
    }

    struct cdb_make cdbm;
    int fd;
    fd = open("tmp.db", O_RDWR | O_CREAT, 0644);
    cdb_make_start(&cdbm, fd);

    argv++;
    argc--;
    char *dbname = *argv;
    argv++;
    argc--;

    int i;
    for(i = 0; i < argc; i++) {
        parse_json(&cdbm, argv[0]); 
        argv++;
    }

    cdb_make_finish(&cdbm);
    rename("tmp.db", dbname);
    close(fd);
    return 0;
}
开发者ID:narner,项目名称:Sporth,代码行数:30,代码来源:cdbjson.c

示例10: on_post_messages_request

static int8_t on_post_messages_request(int8_t cid, GSwifi::GSREQUESTSTATE state) {
    while (! gs.bufferEmpty()) {
        char letter = gs.bufferGet();
        parse_json( letter );
    }

    if (state == GSwifi::GSREQUESTSTATE_RECEIVED) {
        // should be xmitting or idle (xmit finished)
        if (IrCtrl.state == IR_WRITING) {
            HTTPLOG_PRINTLN("!E7");
            // invalid json
            gs.writeHead(cid, 400);
            gs.writeEnd();
        }
        else {
            gs.writeHead(cid, 200);
            gs.writeEnd();
        }
        ring_put( &commands, COMMAND_CLOSE );
        ring_put( &commands, cid );

#ifdef USE_INTERNET
        TIMER_START( suspend_polling_timer, SUSPEND_GET_MESSAGES_INTERVAL );
#endif
    }

    return 0;
}
开发者ID:deton,项目名称:irkit-device,代码行数:28,代码来源:IRKitHTTPHandler.cpp

示例11: main

int
main(void)
{
    jsmntok_t tokens[32];
    memset(tokens, 0, sizeof(tokens));
    const char json[] = "[[\"*\"],[1,2,3,4]]";
    int parsed = parse_json(
        tokens, LGTD_ARRAY_SIZE(tokens), json, sizeof(json)
    );

    struct lgtd_jsonrpc_target_args {
        const jsmntok_t *target;
        int             target_ntokens;
        const jsmntok_t *label;
    } params = { NULL, 0, NULL };
    static const struct lgtd_jsonrpc_node schema[] = {
        LGTD_JSONRPC_NODE(
            "target",
            offsetof(struct lgtd_jsonrpc_target_args, target),
            offsetof(struct lgtd_jsonrpc_target_args, target_ntokens),
            lgtd_jsonrpc_type_string_number_or_array,
            false
        ),
        LGTD_JSONRPC_NODE(
            "label",
            offsetof(struct lgtd_jsonrpc_target_args, label),
            -1,
            // this must dereference json from the what's in the token (see
            // next comment):
            lgtd_jsonrpc_type_number,
            false
        )
    };
开发者ID:aoighost,项目名称:lightsd,代码行数:33,代码来源:test_jsonrpc_extract_values_from_schema_and_array_honors_objsize.c

示例12: parse_json_file

/* Parses the given JSON File 
 * Returns
 *  - 0 on success and all the arguments will be pointing to parsed data
 *  - 1 on failure and garbage elsewhere
 */
int parse_json_file(const char *filename, int *arg_c, int *live, char *user, char *group, char *command) {
  int fd;			/* file descriptor */
  int r = 1;			/* result (default, failure) */
  char json_str[FILE_SIZE+10];	/* file content store */

  /* slurp the file contents */
  fd = open(filename, R_OK);
  if (fd == -1) {
    _LOGGER("(ERROR) Cannot Open File [%s] Reason [%s]", filename, strerror(errno));
    return 1;
  }

  r = read(fd, json_str, FILE_SIZE); /* i should use stat to see file size, this is a possible overflow */
  if (r <= 0 || r >= FILE_SIZE) {
    _LOGGER("File size for file (%s) unexpected expected size (Expected Size:%d)", filename, FILE_SIZE);
    return 1;
  }
  json_str[r] = '\0';		/* more efficient than bzero :-) */

  close(fd);

  r = parse_json(json_str, arg_c, live, user, group, command);

  return r;
}
开发者ID:cloud-hot,项目名称:marionette,代码行数:30,代码来源:json_parser.c

示例13: memset

json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags, json_error_t *error)
{
    lex_t lex;
    json_t *result;

    callback_data_t stream_data;

    memset(&stream_data, 0, sizeof(stream_data));
    stream_data.callback = callback;
    stream_data.arg = arg;

    jsonp_error_init(error, "<callback>");

    if (callback == NULL) {
        error_set(error, NULL, "wrong arguments");
        return NULL;
    }

    if(lex_init(&lex, (get_func)callback_get, &stream_data))
        return NULL;

    result = parse_json(&lex, flags, error);

    lex_close(&lex);
    return result;
}
开发者ID:cryptobiote,项目名称:jansson,代码行数:26,代码来源:load.c

示例14: jsonp_error_init

json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
{
    lex_t lex;
    const char *source;
    json_t *result;
    (void)flags; /* unused */

    if(lex_init(&lex, (get_func)fgetc, input))
        return NULL;

    if(input == stdin)
        source = "<stdin>";
    else
        source = "<stream>";

    jsonp_error_init(error, source);

    result = parse_json(&lex, error);
    if(!result)
        goto out;

    lex_scan(&lex, error);
    if(lex.token != TOKEN_EOF) {
        error_set(error, &lex, "end of file expected");
        json_decref(result);
        result = NULL;
    }

out:
    lex_close(&lex);
    return result;
}
开发者ID:derdewey,项目名称:jansson,代码行数:32,代码来源:load.c

示例15: main

int
main(void)
{
    jsmntok_t tokens[32];
    const char json[] = ("{"
        "\"jsonrpc\": \"2.0\","
        "\"method\": \"power_off\","
        "\"params\": {\"target\": \"*\"},"
        "\"id\": \"42\""
    "}");
    int parsed = parse_json(
        tokens, LGTD_ARRAY_SIZE(tokens), json, sizeof(json)
    );

    bool ok;
    struct lgtd_jsonrpc_request req = TEST_REQUEST_INITIALIZER;
    struct lgtd_client client = {
        .io = NULL, .current_request = &req, .json = json
    };
    ok = lgtd_jsonrpc_check_and_extract_request(&req, tokens, parsed, json);
    if (!ok) {
        errx(1, "can't parse request");
    }

    lgtd_jsonrpc_check_and_call_power_off(&client);

    if (!power_off_called) {
        errx(1, "lgtd_proto_power_off wasn't called");
    }

    return 0;
}
开发者ID:rivy,项目名称:lightsd,代码行数:32,代码来源:test_jsonrpc_check_and_call_power_off.c


注:本文中的parse_json函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。