예제 #1
0
static int
parse_geojson_coord(json_object *poObj, bool *hasz, POINTARRAY *pa)
{
	POINT4D pt;
	int iType = 0;

	POSTGIS_DEBUGF(3, "parse_geojson_coord called for object %s.", json_object_to_json_string( poObj ) );

	if( json_type_array == json_object_get_type( poObj ) )
	{

		json_object* poObjCoord = NULL;
		const int nSize = json_object_array_length( poObj );
		POSTGIS_DEBUGF(3, "parse_geojson_coord called for array size %d.", nSize );


		// Read X coordinate
		poObjCoord = json_object_array_get_idx( poObj, 0 );
		iType = json_object_get_type(poObjCoord);
		if (iType == json_type_double)
			pt.x = json_object_get_double( poObjCoord );
		else
			pt.x = json_object_get_int( poObjCoord );
		POSTGIS_DEBUGF(3, "parse_geojson_coord pt.x = %f.", pt.x );

		// Read Y coordiante
		poObjCoord = json_object_array_get_idx( poObj, 1 );
		if (iType == json_type_double)
			pt.y = json_object_get_double( poObjCoord );
		else
			pt.y = json_object_get_int( poObjCoord );
		POSTGIS_DEBUGF(3, "parse_geojson_coord pt.y = %f.", pt.y );

		*hasz = false;

		if( nSize == 3 )
		{
			// Read Z coordiante
			poObjCoord = json_object_array_get_idx( poObj, 2 );
			if (iType == 3)
				pt.z = json_object_get_double( poObjCoord );
			else
				pt.z = json_object_get_int( poObjCoord );
			POSTGIS_DEBUGF(3, "parse_geojson_coord pt.z = %f.", pt.z );
			*hasz = true;
		}
	}

	return ptarray_append_point(pa, &pt, LW_FALSE);
}
예제 #2
0
파일: main.c 프로젝트: sleep-walker/sway
static void pretty_print_input(json_object *i) {
	json_object *id, *name, *size, *caps;
	json_object_object_get_ex(i, "identifier", &id);
	json_object_object_get_ex(i, "name", &name);
	json_object_object_get_ex(i, "size", &size);
	json_object_object_get_ex(i, "capabilities", &caps);

	printf( "Input device %s\n  Type: ", json_object_get_string(name));

	struct {
		const char *a;
		const char *b;
	} cap_names[] = {
		{ "keyboard", "Keyboard" },
		{ "pointer", "Mouse" },
		{ "touch", "Touch" },
		{ "tablet_tool", "Tablet tool" },
		{ "tablet_pad", "Tablet pad" },
		{ "gesture", "Gesture" },
		{ "switch", "Switch" },
	};

	size_t len = json_object_array_length(caps);
	if (len == 0) {
		printf("Unknown");
	}

	json_object *cap;
	for (size_t i = 0; i < len; ++i) {
		cap = json_object_array_get_idx(caps, i);
		const char *cap_s = json_object_get_string(cap);
		const char *_name = NULL;
		for (size_t j = 0; j < sizeof(cap_names) / sizeof(cap_names[0]); ++i) {
			if (strcmp(cap_names[i].a, cap_s) == 0) {
				_name = cap_names[i].b;
				break;
			}
		}
		printf("%s%s", _name ? _name : cap_s, len > 1 && i != len - 1 ? ", " : "");
	}
	printf("\n  Sway ID: %s\n", json_object_get_string(id));
	if (size) {
		json_object *width, *height;
		json_object_object_get_ex(size, "width", &width);
		json_object_object_get_ex(size, "height", &height);
		printf("  Size: %lfmm x %lfmm\n",
				json_object_get_double(width), json_object_get_double(height));
	}
	printf("\n");
}
예제 #3
0
// check if array of strings in json object is the same or not
int string_array_cmp(struct json_object *a, struct json_object *b)
{
    if (json_object_get_type(a) != json_type_array)
        return -1; // wrong type

    if (json_object_get_type(b) != json_type_array)
        return -1; // wrong type

    if (json_object_array_length(a) != json_object_array_length(b))
        return 1;

    for (int i=0; i<json_object_array_length(a); i++) {
        struct json_object *s_a, *s_b;
        const char *str_a, *str_b;

        s_a = json_object_array_get_idx(a, i);
        if (json_object_get_type(s_a) != json_type_string)
            return -1; // wrong type

        s_b = json_object_array_get_idx(b, i);
        if (json_object_get_type(s_b) != json_type_string)
            return -1; // wrong type

        str_a = json_object_get_string(s_a);
        str_b = json_object_get_string(s_b);
        if (str_a == NULL && str_b == NULL)
            continue;

        if (str_a == NULL || str_b == NULL)
            return 1;

        if (strcmp(str_a, str_b) != 0)
            return 1;
    }

    return 0;
}
예제 #4
0
static gboolean xr_call_unserialize_request_json(xr_call* call, const char* buf, int len)
{
    struct json_tokener* t;
    struct json_object* r;
    int i;

    t = json_tokener_new();
    r = json_tokener_parse_ex(t, (char*)buf, len);
    json_tokener_free(t);

    if (r == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Invalid JSON object.");
        return FALSE;
    }

    call->method = g_strdup(json_object_get_string(json_object_object_get(r, "method")));
    if (call->method == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Missing method.");
        json_object_put(r);
        return FALSE;
    }

    struct json_object* params = json_object_object_get(r, "params");
    if (params == NULL || !json_object_is_type(params, json_type_array))
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Invalid params.");
        json_object_put(r);
        return FALSE;
    }

    const int params_count = json_object_array_length(params);
    for (i = 0; i < params_count; i++)
    {
        xr_value* v = _xr_value_unserialize_json(json_object_array_get_idx(params, i));
        if (v == NULL)
        {
            xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Failed to unserialize parameter %d.", i);
            json_object_put(r);
            return FALSE;
        }

        xr_call_add_param(call, v);
    }

    json_object_put(r);
    return TRUE;
}
예제 #5
0
void loadUltimarcConfigurations (int argc, char **argv)
{
  int idx;
  int inner_idx;

  const char* fileStr = NULL;

  json_object *jobj = NULL;
  json_object *innerobj = NULL;
  json_object *item = NULL;

  for (idx = 1; idx < argc; ++idx)
  {
    jobj = json_object_from_file (argv[idx]);
    if (jobj)
    {
      log_info ("Loading %s...", argv[idx]);

      if (json_object_object_get_ex(jobj, "configurations", &innerobj))
      {
        printf ("\n");
        for (inner_idx = 0; inner_idx < json_object_array_length(innerobj); ++ inner_idx)
        {
          item = json_object_array_get_idx(innerobj, inner_idx);
          fileStr = json_object_get_string(item);
          item = json_object_from_file (fileStr);

          if (item)
          {
            log_info ("Loading %s...", fileStr);
            updateUltimarcBoard(item);
          }
          else
          {
            log_err ("%s. Format invalid\n", fileStr);
          }
        }
      }
      else
      {
        updateUltimarcBoard(jobj);
      }
    }
    else
    {
      log_err ("%s. Format invalid\n", argv[idx]);
    }
  }
}
예제 #6
0
static struct json_object *
jp_match_expr(struct jp_opcode *ptr,
              struct json_object *root, struct json_object *cur,
              jp_match_cb_t cb, void *priv)
{
	int idx, len;
	struct json_object *tmp, *res = NULL;

	switch (json_object_get_type(cur))
	{
	case json_type_object:
		; /* a label can only be part of a statement and a declaration is not a statement */
		json_object_object_foreach(cur, key, val)
		{
			if (jp_expr(ptr, root, val, -1, key, cb, priv))
			{
				tmp = jp_match_next(ptr->sibling, root, val, cb, priv);

				if (tmp && !res)
					res = tmp;
			}
		}

		break;

	case json_type_array:
		len = json_object_array_length(cur);

		for (idx = 0; idx < len; idx++)
		{
			tmp = json_object_array_get_idx(cur, idx);

			if (jp_expr(ptr, root, tmp, idx, NULL, cb, priv))
			{
				tmp = jp_match_next(ptr->sibling, root, tmp, cb, priv);

				if (tmp && !res)
					res = tmp;
			}
		}

		break;

	default:
		break;
	}

	return res;
}
예제 #7
0
bool OGRAmigoCloudDataSource::ListDatasets()
{
    std::stringstream url;
    url << std::string(GetAPIURL()) << "/users/0/projects/" << std::string(GetProjectId()) << "/datasets/?summary";
    json_object* result = RunGET(url.str().c_str());
    if( result == nullptr ) {
        CPLError(CE_Failure, CPLE_AppDefined, "AmigoCloud:get failed.");
        return false;
    }

    if( result != nullptr )
    {
        auto type = json_object_get_type(result);
        if(type == json_type_object)
        {
            json_object *poResults = CPL_json_object_object_get(result, "results");
            if(poResults != nullptr &&
                json_object_get_type(poResults) == json_type_array)
            {
                CPLprintf("List of available datasets for project id: %s\n", GetProjectId());
                CPLprintf("| id \t | name\n");
                CPLprintf("|--------|-------------------\n");
                const auto nSize = json_object_array_length(poResults);
                for(auto i = decltype(nSize){0}; i < nSize; ++i) {
                    json_object *ds = json_object_array_get_idx(poResults, i);
                    if(ds!=nullptr) {
                        const char *name = nullptr;
                        int64_t dataset_id = 0;
                        json_object *poName = CPL_json_object_object_get(ds, "name");
                        if (poName != nullptr) {
                            name = json_object_get_string(poName);
                        }
                        json_object *poId = CPL_json_object_object_get(ds, "id");
                        if (poId != nullptr) {
                            dataset_id = json_object_get_int64(poId);
                        }
                        if (name != nullptr) {
                            std::stringstream str;
                            str << "| " << dataset_id << "\t | " << name;
                            CPLprintf("%s\n", str.str().c_str());
                        }
                    }
                }
            }
        }
        json_object_put(result);
    }
    return true;
}
//FIXME GC corresponding C object when JS object is free.
ArrayContainer json_native_object_array_to_container(json_object* json_array) {
  int i;
  ArrayContainer ret;
  int array_length = json_object_array_length(json_array);
  void** array = g_new0(void*, array_length); // The C implementation should be responsible for free it.
  ret.num = array_length;
  ret.data = (void*)array;

  for (i = 0; i < array_length; ++i) {
    json_object *obj = json_object_array_get_idx(json_array, i);
    void* obj_ptr = (void*)json_object_get_int64(obj);
    array[i] = obj_ptr;
  }
  return ret;
}
예제 #9
0
파일: json.c 프로젝트: sleep-walker/sway
char *get_focused_output() {
	json_object *outputs, *output, *name;
	json_object_object_get_ex(tree, "nodes", &outputs);

	for (int i = 0; i < json_object_array_length(outputs); i++) {
		output = json_object_array_get_idx(outputs, i);

		if (get_focused_container_r(output)) {
			json_object_object_get_ex(output, "name", &name);
			return strdup(json_object_get_string(name));
		}
	}

	return NULL;
}
예제 #10
0
파일: json.c 프로젝트: sleep-walker/sway
json_object *get_output_container(const char *output) {
	json_object *outputs, *json_output, *name;
	json_object_object_get_ex(tree, "nodes", &outputs);

	for (int i = 0; i < json_object_array_length(outputs); i++) {
		json_output = json_object_array_get_idx(outputs, i);
		json_object_object_get_ex(json_output, "name", &name);

		if (strcmp(json_object_get_string(name), output) == 0) {
			return json_output;
		}
	}

	return NULL;
}
예제 #11
0
void array( json_object *jo, char *key, mxArray ** mxa) {

    enum json_type type;
    int i;
    int len;

    struct json_object *jv;
    struct json_object *ja = jo;

    mxArray *ma;

    if(key){ 
        ja = json_object_object_get(jo, key);
    }

    len = json_object_array_length(ja); 

    *mxa = mxCreateCellMatrix(len, 1);

    for (i=0; i< len; i++){

        jv = json_object_array_get_idx(ja, i); 

        if(jv){
            type = json_object_get_type(jv);

            if (type == json_type_array) {
                array(jv, NULL, &ma);
            }

            else if (type != json_type_object) {
                value(jv, &ma);
            }

            else {
                object(jv, &ma);
            }
        }
        else{
            ma = mxCreateDoubleScalar(mxGetNaN());
        }

        mxSetCell(*mxa, i, ma);

    }


}
예제 #12
0
void asterisk_acc_unpack_socket(char *buff, perm_node_t **key_list, asterisk_acc_table_t *asterisk_acc_table, opool_t *opool) {
    int i;
    json_object *new_obj, *jvalue;
    opool_item_t *item, *item2;
    perm_node_t *key_element, *value_element, *data_list;

    perm_node_t *temp, *entry;
    perm_node_t *temp2, *entry2;
    perm_node_t *data_list2;

    char id[10], pwd[10];

	new_obj = json_tokener_parse(buff);
	//printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));

    for(i = 0; i < json_object_array_length(new_obj); i++)
	{ 
        item = opool_get(opool);
        EXIT_IF_TRUE(item == NULL, "Cannot get from object pool\n");
        key_element = (perm_node_t *)item->data;

        item2 = opool_get(opool);
        EXIT_IF_TRUE(item == NULL, "Cannot get from object pool\n");
        value_element = (perm_node_t *)item2->data;

        json_object *obj = json_object_array_get_idx(new_obj, i);

        json_object_object_get_ex(obj, "account", &jvalue);
        strcpy(id, json_object_get_string(jvalue));

        json_object_object_get_ex(obj, "password", &jvalue);
        strcpy(pwd, json_object_get_string(jvalue));

        ansi_copy_str(key_element->value, id);
        ansi_copy_str(value_element->value, pwd);

        data_list = (perm_node_t *)ht_get_item(asterisk_acc_table, (void *)id);
        if (data_list == NULL) {
            DL_APPEND(*key_list, key_element);
            DL_APPEND(data_list, value_element);
            ht_add_item(asterisk_acc_table, id, data_list);
        }
        else {
            DL_APPEND(data_list, value_element);
        }
    }

}
예제 #13
0
파일: conf.c 프로젝트: cubicdaiya/neoagent
char *na_conf_get_environment_name(struct json_object *environments_obj, int idx)
{
    struct json_object *environment_obj;
    struct json_object *param_obj;
    int l;

    l = json_object_array_length(environments_obj);

    if (idx >= l) {
        return NULL;
    }

    environment_obj = json_object_array_get_idx(environments_obj, idx);
    param_obj       = json_object_object_get(environment_obj, "name");
    return (char *)json_object_get_string(param_obj);
}
예제 #14
0
static void ParseMultiPolygon(OGRMultiPolygon* poMultiPoly, json_object* poArcsObj,
                         json_object* poArcsDB, ScalingParams* psParams)
{
    int nPolys = json_object_array_length(poArcsObj);
    for(int i=0; i<nPolys; i++)
    {
        OGRPolygon* poPoly = new OGRPolygon();
        poMultiPoly->addGeometryDirectly(poPoly);

        json_object* poPolyArcs = json_object_array_get_idx(poArcsObj, i);
        if( poPolyArcs != NULL && json_type_array == json_object_get_type(poPolyArcs) )
        {
            ParsePolygon(poPoly, poPolyArcs, poArcsDB, psParams);
        }
    }
}
예제 #15
0
static void ParsePolygon(OGRPolygon* poPoly, json_object* poArcsObj,
                         json_object* poArcsDB, ScalingParams* psParams)
{
    int nRings = json_object_array_length(poArcsObj);
    for(int i=0; i<nRings; i++)
    {
        OGRLinearRing* poLR = new OGRLinearRing();
        poPoly->addRingDirectly(poLR);

        json_object* poRing = json_object_array_get_idx(poArcsObj, i);
        if( poRing != NULL && json_type_array == json_object_get_type(poRing) )
        {
            ParseLineString(poLR, poRing, poArcsDB, psParams);
        }
    }
}
예제 #16
0
static void ParseMultiLineString(OGRMultiLineString* poMLS, json_object* poArcsObj,
                                 json_object* poArcsDB, ScalingParams* psParams)
{
    int nRings = json_object_array_length(poArcsObj);
    for(int i=0; i<nRings; i++)
    {
        OGRLineString* poLS = new OGRLineString();
        poMLS->addGeometryDirectly(poLS);

        json_object* poRing = json_object_array_get_idx(poArcsObj, i);
        if( poRing != NULL && json_type_array == json_object_get_type(poRing) )
        {
            ParseLineString(poLS, poRing, poArcsDB, psParams);
        }
    }
}
예제 #17
0
PersistentWindowCache::PersistentWindowCache()
{
	json_object* json = json_object_from_file((char*) kPersistentWindowConf);
	if (!json || is_error(json))
		return;

	json_object_object_foreach(json, key, value) {
		int numItems = json_object_array_length(value);
		for (int i = 0; i < numItems; i++) {
			const char* val = json_object_get_string(json_object_array_get_idx(value, i));;;;
			g_message("Adding persistent window pair: appid: %s, windowname: %s",
				   key, val);
			AppWindowNamePair entry(key, val);
			m_persistableWindowIdentifiers.insert(entry);
		}
	}
예제 #18
0
파일: series.c 프로젝트: radcheb/influxdb-c
size_t
influxdb_series_from_json(json_object *jo, s_influxdb_series ***series)
{
    size_t i, len = json_object_array_length(jo);

    *series = malloc(sizeof (s_influxdb_series *) * len);

    for (i = 0; i < len; i++)
    {
        (*series)[i] = influxdb_serie_from_json(
            json_object_array_get_idx(jo, i)
            );
    }

    return len;
}
예제 #19
0
int pa_format_info_get_prop_string_array(const pa_format_info *f, const char *key, char ***values, int *n_values) {
    const char *str;
    json_object *o, *o1;
    int i, ret = -PA_ERR_INVALID;

    pa_assert(f);
    pa_assert(key);
    pa_assert(values);
    pa_assert(n_values);

    str = pa_proplist_gets(f->plist, key);
    if (!str)
        return -PA_ERR_NOENTITY;

    o = json_tokener_parse(str);
    if (is_error(o)) {
        pa_log_debug("Failed to parse format info property '%s'.", key);
        return -PA_ERR_INVALID;
    }

    if (json_object_get_type(o) != json_type_array)
        goto out;

    *n_values = json_object_array_length(o);
    *values = pa_xnew(char *, *n_values);

    for (i = 0; i < *n_values; i++) {
        o1 = json_object_array_get_idx(o, i);

        if (json_object_get_type(o1) != json_type_string) {
            json_object_put(o1);
            goto out;
        }

        (*values)[i] = pa_xstrdup(json_object_get_string(o1));
        json_object_put(o1);
    }

    ret = 0;

out:
    if (ret < 0)
        pa_log_debug("Format info property '%s' is not a valid string array.", key);

    json_object_put(o);
    return ret;
}
예제 #20
0
telebot_error_e telebot_parser_get_updates(struct json_object *obj,
        telebot_update_t **updates, int *count)
{
    if (obj == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;

    if (updates == NULL)
        return TELEBOT_ERROR_INVALID_PARAMETER;

    struct json_object *array = obj;
    int array_len = json_object_array_length(array);
    if (!array_len)
        return TELEBOT_ERROR_OPERATION_FAILED;

    telebot_update_t *tmp = calloc(array_len, sizeof(telebot_update_t));
    if (tmp == NULL)
        return TELEBOT_ERROR_OUT_OF_MEMORY;

    *count = array_len;
    *updates = tmp;

    int index;
    for (index=0;index<array_len;index++) {
        struct json_object *item = json_object_array_get_idx(array, index);

        memset(&(tmp[index].message), 0, sizeof(telebot_message_t));
        tmp[index].update_id = 0;

        struct json_object *update_id;
        if (json_object_object_get_ex(item, "update_id", &update_id)) {
            tmp[index].update_id = json_object_get_int(update_id);
            json_object_put(update_id);
        }

        struct json_object *message;
        if (json_object_object_get_ex(item, "message", &message)) {
            if (telebot_parser_get_message(message, &(tmp[index].message)) !=
                    TELEBOT_ERROR_NONE)
                ERR("Failed to parse message of bot update");
            json_object_put(message);
        }

        json_object_put(item);
    }

    return TELEBOT_ERROR_NONE;
}
예제 #21
0
파일: etvnet.c 프로젝트: serge-v/ctv
static struct movie_list *
load()
{
	char url[500];
	json_object *root, *folders, *folder;
	int i;

	provider->error_number = 0;
	snprintf(url, 499, "%s/video/bookmarks/folders.json?per_page=20", api_root);

	root = get_cached(url, "favorites");
	if (provider->error_number != 0)
		return NULL;

	folders = get_data(root, "folders");
	int folders_count = json_object_array_length(folders);
	int folder_id = 0;

	for (i = 0; i < folders_count; i++) {
		folder = json_object_array_get_idx(folders, i);
		if (folder == NULL) {
			sprintf(last_error, "Cannot get folder[%d]", i);
			provider->error_number = 1;
			return  NULL;
		}

		const char *title = get_str(folder, "title");
		if (strcmp(title, "serge") == 0) {
			folder_id = get_int(folder, "id");
			break;
		}
	}

	if (folder_id == 0) {
		sprintf(last_error, "cannot get my favorite folder");
		provider->error_number = 1;
		return NULL;
	}

	root = fetch_favorite(folder_id);
	if (provider->error_number != 0)
		return NULL;

	struct movie_list *list = parse_favorites(root);

	return list;
}
예제 #22
0
static int
ln_addField_Syslog(char *name, struct json_object *field, es_str_t **str)
{
    int r;
    const char *value;
    int needComma = 0;
    struct json_object *obj;
    int i;

    assert(field != NULL);
    assert(str != NULL);
    assert(*str != NULL);

    CHKR(es_addBuf(str, name, strlen(name)));
    CHKR(es_addBuf(str, "=\"", 2));
    switch(json_object_get_type(field)) {
    case json_type_array:
        for (i = json_object_array_length(field) - 1; i >= 0; i--) {
            if(needComma)
                es_addChar(str, ',');
            else
                needComma = 1;
            CHKN(obj = json_object_array_get_idx(field, i));
            CHKN(value = json_object_get_string(obj));
            CHKR(ln_addValue_Syslog(value, str));
        }
        break;
    case json_type_string:
    case json_type_int:
        CHKN(value = json_object_get_string(field));
        CHKR(ln_addValue_Syslog(value, str));
        break;
    case json_type_null:
    case json_type_boolean:
    case json_type_double:
    case json_type_object:
        CHKR(es_addBuf(str, "***unsupported type***", sizeof("***unsupported type***")-1));
        break;
    default:
        CHKR(es_addBuf(str, "***OBJECT***", sizeof("***OBJECT***")-1));
    }
    CHKR(es_addChar(str, '\"'));
    r = 0;

done:
    return r;
}
void QblJsonMainConfigUploadArray::parse(json_object *obj)
{
    int i, length;
    json_object *value;

    length = json_object_array_length(obj);
    for (i = 0; i < length; i++) {
        QblJsonMainConfigUpload *upload;

        value = json_object_array_get_idx(obj, i);
        upload = new QblJsonMainConfigUpload();
        upload->parse(value);
        this->list.push_back((QblJsonObject *) upload);
    }

    return;
}
예제 #24
0
bool OGRESRIJSONReader::GenerateLayerDefn()
{
    CPLAssert( nullptr != poGJObject_ );
    CPLAssert( nullptr != poLayer_->GetLayerDefn() );
    CPLAssert( 0 == poLayer_->GetLayerDefn()->GetFieldCount() );

    bool bSuccess = true;

/* -------------------------------------------------------------------- */
/*      Scan all features and generate layer definition.                */
/* -------------------------------------------------------------------- */
    json_object* poFields =
        OGRGeoJSONFindMemberByName( poGJObject_, "fields" );
    if( nullptr != poFields &&
        json_type_array == json_object_get_type( poFields ) )
    {
        const int nFeatures = json_object_array_length( poFields );
        for( int i = 0; i < nFeatures; ++i )
        {
            json_object* poField =
                json_object_array_get_idx( poFields, i );
            if( !ParseField( poField ) )
            {
                CPLDebug( "GeoJSON", "Create feature schema failure." );
                bSuccess = false;
            }
        }
    }
    else
    {
        poFields = OGRGeoJSONFindMemberByName(
            poGJObject_, "fieldAliases" );
        if( nullptr != poFields &&
            json_object_get_type(poFields) == json_type_object )
        {
            OGRFeatureDefn* poDefn = poLayer_->GetLayerDefn();
            json_object_iter it;
            it.key = nullptr;
            it.val = nullptr;
            it.entry = nullptr;
            json_object_object_foreachC( poFields, it )
            {
                OGRFieldDefn fldDefn( it.key, OFTString );
                poDefn->AddFieldDefn( &fldDefn );
            }
        }
예제 #25
0
파일: example.c 프로젝트: jiajuwu/JSON
json_bool fill_data_in_array(json_object *json_jobj, int *int_field, char *field_name)
{
	json_object *new_jobj = NULL;
	json_object *array_jobj = NULL;
	json_bool res = false;	
	int array_len = 0;
	int index = 0;
	if ((res = json_object_object_get_ex(json_jobj, field_name, &new_jobj))) {
        array_len = json_object_array_length(new_jobj);
        for (index = 0; index < array_len; index++)
        {
            array_jobj = json_object_array_get_idx(new_jobj, index);
            int_field[index] = json_object_get_int(array_jobj);
        }
    }
	return res;
}
예제 #26
0
/******************************************************************************
 *                                                                            *
 * Function:                                                                  *
 *                                                                            *
 * Purpose:                                                                   *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int ja_extjob_script(ja_job_object * job)
{
    int ret;
    json_object *jp_arg, *jp;
    int i;
    char *cmd;
    const char *__function_name = "ja_extjob_script";

    zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
    ret = FAIL;
    jp_arg = json_tokener_parse(job->argument);
    if (is_error(jp_arg)) {
        jp_arg = NULL;
        zbx_snprintf(job->message, sizeof(job->message),
                     "Can not parse job argument [%s]", job->argument);
        goto error;
    }

    if (json_object_get_type(jp_arg) != json_type_array) {
        zbx_snprintf(job->message, sizeof(job->message),
                     "[%s] is not an array", job->argument);
        goto error;
    }

    cmd =
        zbx_dsprintf(NULL, "\"%s%c%s.%s\"", CONFIG_EXTJOB_PATH, JA_DLM,
                     job->script, JA_EXE);
    zbx_snprintf(job->script, sizeof(job->script), "%s", cmd);
    zbx_free(cmd);
    for (i = 0; i < json_object_array_length(jp_arg); i++) {
        jp = json_object_array_get_idx(jp_arg, i);
        cmd =
            zbx_dsprintf(NULL, "%s \"%s\"", job->script,
                         json_object_get_string(jp));
        zbx_snprintf(job->script, sizeof(job->script), "%s", cmd);
        zbx_free(cmd);
    }

    ret = SUCCEED;

  error:
    json_object_put(jp_arg);
    return ret;


}
void QblJsonMainConfigContactArray::parse(json_object *obj)
{
    int i, length;
    json_object *value;

    length = json_object_array_length(obj);
    for (i = 0; i < length; i++) {
        QblJsonMainConfigContact *contact;

        value = json_object_array_get_idx(obj, i);
        contact = new QblJsonMainConfigContact();
        contact->parse(value);
        this->list.push_back((QblJsonObject *) contact);
    }

    return;
}
예제 #28
0
파일: json.c 프로젝트: OpenSIPS/opensips
int pv_json_iterate(json_t **obj, pv_param_t *pvp, json_name *id, pv_value_t *val)
{
	json_iter_t iter_end;

	if (json_object_is_type(*obj, json_type_object)) {

		if (pvp->pvi.u.ival != id->iter_prev_idx + 1) {
			id->iter_prev_idx = 0;
			id->iter = json_object_iter_begin(*obj);
		} else
			id->iter_prev_idx++;

		iter_end = json_object_iter_end(*obj);
		if (json_object_iter_equal(&id->iter, &iter_end))
			return pv_get_null(NULL, pvp, val);

		if (id->iter_type == ITER_KEYS) {
			val->flags = PV_VAL_STR;
			val->rs.s = (char *)json_object_iter_peek_name(&id->iter);
			val->rs.len = strlen(val->rs.s);
		} else
			*obj = json_object_iter_peek_value(&id->iter);

		json_object_iter_next(&id->iter);	

	} else if (json_object_is_type(*obj, json_type_array)) {

		if (id->iter_type != ITER_NONE) {
			LM_DBG("Invalid object-like iteration for arrays\n");
			return -1;
		}

		if (pvp->pvi.u.ival == json_object_array_length(*obj)) {
			id->iter_prev_idx = 0;
			return pv_get_null(NULL, pvp, val);
		}

		*obj = json_object_array_get_idx(*obj, pvp->pvi.u.ival);

	} else {
		LM_DBG("Can only iterate over arrays or objects\n");
		return -1;
	}

	return 0;
}
예제 #29
0
static void OGRGeoJSONPatchArray( json_object* poJSonArray,
                                  json_object* poNativeArray,
                                  int nDepth )
{
    if( nDepth == 0 )
    {
        OGRGeoJSONPatchPosition(poJSonArray, poNativeArray);
        return;
    }
    int nLength = json_object_array_length(poJSonArray);
    for(int i=0; i<nLength;i++)
    {
        json_object* poJSonChild = json_object_array_get_idx(poJSonArray, i);
        json_object* poNativeChild = json_object_array_get_idx(poNativeArray, i);
        OGRGeoJSONPatchArray(poJSonChild, poNativeChild,nDepth-1);
    }
}
예제 #30
0
파일: conf.c 프로젝트: cubicdaiya/neoagent
int na_conf_get_environment_idx(struct json_object *environments_obj, char *envname)
{
    struct json_object *environment_obj;
    struct json_object *param_obj;
    int l;

    l = json_object_array_length(environments_obj);

    for (int i=0;i<l;++i) {
        environment_obj = json_object_array_get_idx(environments_obj, i);
        param_obj       = json_object_object_get(environment_obj, "name");
        if (strcmp(envname, json_object_get_string(param_obj)) == 0) {
            return i;
        }
    }
    return -1;
}