目前分類:json (2)

瀏覽方式: 標題列表 簡短摘要
struct stat sb;
struct json_object *json, *obj;
char url[128], file[128], *buff;
int  fd=0, value=0;

snprintf(file, 127, "/tmp/%d_ipcam.json", (int)pthread_self());
snprintf(url, 127, "http://%s:%d/tmp/sapido/ipcam_schedule/%d.json", ip, port, index);
if (wget(url, file) == 0) {
    do {
        fd = open(file, O_RDONLY);
        if (fd < 0) continue;
        if (fstat(fd, &sb) < 0) continue;
        buff = (char*) mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
        if (buff == MAP_FAILED) continue;
        json = json_tokener_parse(buff);
        if (!is_error(json)) {
            obj = json_object_object_get(json, "format");
            if (obj != NULL) value = json_object_get_int(obj);
            json_object_put(json);
        }
        munmap(buff, sb.st_size);
    } while (0);
    if (fd) close(fd);
}
printf("value: %d\n", value);
return value;

台南小新 發表在 痞客邦 PIXNET 留言(0) 人氣()

json-c wiki: https://github.com/json-c/json-c/wiki

json-c download: https://s3.amazonaws.com/json-c_releases/releases/index.html

台南小新 發表在 痞客邦 PIXNET 留言(0) 人氣()