示例#1
0
std::map<std::string, std::vector<std::string>> newsblur_api::mk_feeds_to_tags(
json_object * folders)
{
	std::map<std::string, std::vector<std::string>> result;
	array_list * tags = json_object_get_array(folders);
	int tags_len = array_list_length(tags);
	for (int i = 0; i < tags_len; ++i) {
		json_object * tag_to_feed_ids = json_object_array_get_idx(folders, i);

		if (!json_object_is_type(tag_to_feed_ids, json_type_object))
			// "folders" array contains not only dictionaries describing
			// folders but also numbers, which are IDs of feeds that don't
			// belong to any folder. This check skips these IDs.
			continue;

		json_object_object_foreach(tag_to_feed_ids, key, feeds_with_tag_obj) {
			std::string std_key(key);
			array_list * feeds_with_tag_arr = json_object_get_array(feeds_with_tag_obj);
			int feeds_with_tag_len = array_list_length(feeds_with_tag_arr);
			for (int j = 0; j < feeds_with_tag_len; ++j) {
				json_object * feed_id_obj = json_object_array_get_idx(feeds_with_tag_obj, j);
				std::string feed_id(json_object_get_string(feed_id_obj));
				result[feed_id].push_back(std_key);
			}
		}
	}
示例#2
0
/* Testing correctness of parsed values */
void test_suite_2(JSON_Value *root_value) {
    JSON_Object *root_object;
    JSON_Array *array;
    size_t i;
    TEST(root_value);
    TEST(json_value_get_type(root_value) == JSONObject);
    root_object = json_value_get_object(root_value);
    TEST(STREQ(json_object_get_string(root_object, "string"), "lorem ipsum"));
    TEST(STREQ(json_object_get_string(root_object, "utf string"), "lorem ipsum"));
    TEST(STREQ(json_object_get_string(root_object, "utf-8 string"), "あいうえお"));
    TEST(STREQ(json_object_get_string(root_object, "surrogate string"), "lorem𝄞ipsum𝍧lorem"));
    TEST(json_object_get_number(root_object, "positive one") == 1.0);
    TEST(json_object_get_number(root_object, "negative one") == -1.0);
    TEST(json_object_get_number(root_object, "hard to parse number") == -0.000314);
    TEST(json_object_get_boolean(root_object, "boolean true") == 1);
    TEST(json_object_get_boolean(root_object, "boolean false") == 0);
    TEST(json_value_get_type(json_object_get_value(root_object, "null")) == JSONNull);
    
    array = json_object_get_array(root_object, "string array");
    if (array != NULL && json_array_get_count(array) > 1) {
        TEST(STREQ(json_array_get_string(array, 0), "lorem"));
        TEST(STREQ(json_array_get_string(array, 1), "ipsum"));
    } else {
        tests_failed++;
    }
    
    array = json_object_get_array(root_object, "x^2 array");
    if (array != NULL) {
        for (i = 0; i < json_array_get_count(array); i++) {
            TEST(json_array_get_number(array, i) == (i * i));
        }
    } else {
        tests_failed++;
    }
    
    TEST(json_object_get_array(root_object, "non existent array") == NULL);
    TEST(STREQ(json_object_dotget_string(root_object, "object.nested string"), "str"));
    TEST(json_object_dotget_boolean(root_object, "object.nested true") == 1);
    TEST(json_object_dotget_boolean(root_object, "object.nested false") == 0);
    TEST(json_object_dotget_value(root_object, "object.nested null") != NULL);
    TEST(json_object_dotget_number(root_object, "object.nested number") == 123);
    
    TEST(json_object_dotget_value(root_object, "should.be.null") == NULL);
    TEST(json_object_dotget_value(root_object, "should.be.null.") == NULL);
    TEST(json_object_dotget_value(root_object, ".") == NULL);
    TEST(json_object_dotget_value(root_object, "") == NULL);
    
    array = json_object_dotget_array(root_object, "object.nested array");
    if (array != NULL && json_array_get_count(array) > 1) {
        TEST(STREQ(json_array_get_string(array, 0), "lorem"));
        TEST(STREQ(json_array_get_string(array, 1), "ipsum"));
    } else {
        tests_failed++;
    }
    TEST(json_object_dotget_boolean(root_object, "nested true"));
    
    TEST(STREQ(json_object_get_string(root_object, "/**/"), "comment"));
    TEST(STREQ(json_object_get_string(root_object, "//"), "comment"));
}
bool Bitmaszyna::getAccountInfo()
{
    struct json_object *json,*jtmp,*jtmp2,*jtmp3;
    struct array_list *arr,*arr2;
    int i,j;

    curl_mutex.lock();
    if (makeApiCall("accountInfo",&json,string("nonce=")+to_stringl(getctime()).toStdString()))
    {
        if (!fetchData(&json,&jtmp)) return(false);
        log(string(chunk.memory)+"\n");
        json_object_object_get_ex(json,"deposits",&jtmp);
        arr=json_object_get_array(jtmp);
        deposits.clear();
        for(i=0;i<arr->length;i++)
        {
            Deposit d;

            jtmp2=(struct json_object *)array_list_get_idx(arr,i);
            json_object_object_get_ex(jtmp2,"currency",&jtmp3);
            d.currency=json_object_get_string(jtmp3);
            json_object_object_get_ex(jtmp2,"bank_name",&jtmp3);
            d.bank_name=json_object_get_string(jtmp3);
            json_object_object_get_ex(jtmp2,"pay_to",&jtmp3);
            d.pay_to=json_object_get_string(jtmp3);
            json_object_object_get_ex(jtmp2,"acc_num",&jtmp3);
            d.acc_num=json_object_get_string(jtmp3);
            json_object_object_get_ex(jtmp2,"swift_code",&jtmp3);
            d.swift_code=json_object_get_string(jtmp3);
            json_object_object_get_ex(jtmp2,"transfer_title",&jtmp3);
            d.transfer_title=json_object_get_string(jtmp3);
            deposits.push_back(d);
        }
        json_object_object_get_ex(json,"withdrawalAccounts",&jtmp);
        arr=json_object_get_array(jtmp);
        for(j=0;j<arr->length;j++)
        {
            withdrawalaccounts[j].clear();
            arr2=json_object_get_array((struct json_object *)array_list_get_idx(arr,j));
            for(i=0;i<arr2->length;)
            {
                WithdrawalAccount w;
                jtmp2=(struct json_object *)array_list_get_idx(arr2,i);
                w.account=json_object_get_string(jtmp2);
                i++;
                jtmp2=(struct json_object *)array_list_get_idx(arr2,i);
                w.name=json_object_get_string(jtmp2);
                i++;
                if (w.account.size()>0) withdrawalaccounts[adjustCurrency(j)].push_back(w);
            }
        }
        json_object_put(json);
        logged=true;
        curl_mutex.unlock();
        return(true);
    }
    curl_mutex.unlock();
    return(false);
}
示例#4
0
文件: tests.c 项目: lkunemail/parson
/* Testing correctness of parsed values */
void test_suite_2(void) {
    JSON_Value *root_value;
    JSON_Object *object;
    JSON_Array *array;
    int i;
    const char *filename = "tests/test_2.txt";
    printf("Testing %s:\n", filename);
    root_value = json_parse_file(filename);
    TEST(root_value);
    TEST(json_value_get_type(root_value) == JSONObject);
    object = json_value_get_object(root_value);
    TEST(STREQ(json_object_get_string(object, "string"), "lorem ipsum"));
    TEST(STREQ(json_object_get_string(object, "utf string"), "lorem ipsum"));
    TEST(json_object_get_number(object, "positive one") == 1.0);
    TEST(json_object_get_number(object, "negative one") == -1.0);
    TEST(json_object_get_number(object, "hard to parse number") == -0.000314);
    TEST(json_object_get_boolean(object, "boolean true") == 1);
    TEST(json_object_get_boolean(object, "boolean false") == 0);
    TEST(json_value_get_type(json_object_get_value(object, "null")) == JSONNull);
    
    array = json_object_get_array(object, "string array");
    if (array != NULL && json_array_get_count(array) > 1) {
        TEST(STREQ(json_array_get_string(array, 0), "lorem"));
        TEST(STREQ(json_array_get_string(array, 1), "ipsum"));
    } else {
        tests_failed++;
    }
    
    array = json_object_get_array(object, "x^2 array");
    if (array != NULL) {
        for (i = 0; i < json_array_get_count(array); i++) {
            TEST(json_array_get_number(array, i) == (i * i));
        }
    } else {
        tests_failed++;
    }
    
    TEST(json_object_get_array(object, "non existent array") == NULL);
    TEST(STREQ(json_object_dotget_string(object, "object.nested string"), "str"));
    TEST(json_object_dotget_boolean(object, "object.nested true") == 1);
    TEST(json_object_dotget_boolean(object, "object.nested false") == 0);
    TEST(json_object_dotget_value(object, "object.nested null") != NULL);
    TEST(json_object_dotget_number(object, "object.nested number") == 123);
    
    TEST(json_object_dotget_value(object, "should.be.null") == NULL);
    TEST(json_object_dotget_value(object, "should.be.null.") == NULL);
    TEST(json_object_dotget_value(object, ".") == NULL);
    TEST(json_object_dotget_value(object, "") == NULL);
    
    array = json_object_dotget_array(object, "object.nested array");
    if (array != NULL && json_array_get_count(array) > 1) {
        TEST(STREQ(json_array_get_string(array, 0), "lorem"));
        TEST(STREQ(json_array_get_string(array, 1), "ipsum"));
    } else {
        tests_failed++;
    }
    TEST(json_object_dotget_boolean(object, "nested true"));    
    json_value_free(root_value);
}
示例#5
0
void test_suite_precincts(JSON_Value *root_value) {
    JSON_Object *root_object;
    JSON_Array *array;

    TEST(root_value);
    TEST(json_value_get_type(root_value) == JSONObject);
    root_object = json_value_get_object(root_value);

    unsigned int number_of_precincts = (int) json_object_get_number(root_object, "number_of_precincts");
    printf("number_of_precincts: %d\n", number_of_precincts);

    TEST(number_of_precincts == 60);

    array = json_object_get_array(root_object, "precincts");
    if (array != NULL && json_array_get_count(array) == number_of_precincts) {
        JSON_Object *precinct_object;
        JSON_Array *layers_array;
        int id, coord_x, coord_y;
        unsigned int j;
        
        for(j = 0; j < number_of_precincts; j++) {
            
            precinct_object = json_array_get_object(array, j);
            id = (int) json_object_get_number(precinct_object, "id");
            coord_x = (int) json_object_get_number(precinct_object, "coord_x");
            coord_y = (int) json_object_get_number(precinct_object, "coord_y");

            printf("id: %d \t coord_x: %d \t coord_y: %d\n", id, coord_x, coord_y);

            layers_array = json_object_get_array(precinct_object, "layers");
            if (layers_array != NULL && json_array_get_count(layers_array) >= 1) {
                JSON_Object *layer_object;
                int ql, bytes, psnr;
                unsigned k;

                for(k = 0; k < json_array_get_count(layers_array); k++) {

                    layer_object = json_array_get_object(layers_array, k);
                    ql = (int) json_object_get_number(layer_object, "ql");
                    bytes = (int) json_object_get_number(layer_object, "bytes");
                    psnr = (int) json_object_get_number(layer_object, "psnr");

                    printf("\tql: %d \t bytes: %d \t psnr: %d\n", ql, bytes, psnr);
                }
                
            } else {

            }

        }
    } else {
        tests_failed++;
    }
}
bool Bitmaszyna::getdepth(string market,Tables& tables)
{

    struct json_object *json,*jtmp;
    struct array_list *arr,*arr2;
    int i;
    double sum;

    curl_mutex.lock();
    tables.bids.clear();
    tables.asks.clear();
    if (getTickerData(market+"/depthSimple.json",&json))
    {
        json_object_object_get_ex(json,"bids",&jtmp);
        arr=json_object_get_array(jtmp);
        sum=0.0;
        for(i=0;i<arr->length;i++)
        {
            Offer offer;
            jtmp=(struct json_object *)array_list_get_idx(arr,i);
            arr2=json_object_get_array(jtmp);
            offer.type=BID;
            offer.price=json_object_get_double((struct json_object *)array_list_get_idx(arr2,0));
            offer.amount=json_object_get_double((struct json_object *)array_list_get_idx(arr2,1));
            offer.sum=sum;
            sum+=offer.amount;
            tables.bids.push_back(offer);
        }
        json_object_object_get_ex(json,"asks",&jtmp);
        arr=json_object_get_array(jtmp);
        sum=0.0;
        for(i=0;i<arr->length;i++)
        {
            Offer offer;
            jtmp=(struct json_object *)array_list_get_idx(arr,i);
            arr2=json_object_get_array(jtmp);
            offer.type=BID;
            offer.price=json_object_get_double((struct json_object *)array_list_get_idx(arr2,0));
            offer.amount=json_object_get_double((struct json_object *)array_list_get_idx(arr2,1));
            offer.sumLower=sum;
            sum+=offer.amount*offer.price;
            tables.asks.push_back(offer);
        }
        json_object_put(json);
        curl_mutex.unlock();
        return(true);
    }
    curl_mutex.unlock();
    return(false);
}
示例#7
0
void send_poll_request(State * state, unsigned long id) {
	pthread_mutex_lock(&state->mState);
	state->message = perform_curl(state->message, POLL_CALL, PORT, id, NULL);
	if (!state->message->data) {
		printf("Poll request got null response\n");
		pthread_mutex_unlock(&state->mState);
		return;
	}
	struct json_object * poll_data = json_tokener_parse(state->message->data);
	if (!poll_data) {
		printf("The response string could not be parsed: %s\n", state->message->data);
		pthread_mutex_unlock(&state->mState);
		return;
	}
	pthread_mutex_unlock(&state->mState);

	int i;
	struct json_object * price_array;
	if (json_object_object_get_ex(poll_data, "prices", &price_array) && json_object_get_array(price_array)) {
		clear_state_changed(state);
		for (i = 0; i < json_object_array_length(price_array); ++i) {
			struct json_object * instrument = json_object_array_get_idx(price_array, i);
			struct json_object * name_obj;
			if (json_object_object_get_ex(instrument, "instrument", &name_obj)) {
				setup_instrument(state, json_object_get_string(name_obj), instrument);
			}
		}
		mark_ready(state);
	}
	json_object_put(poll_data);
}
bool Bitmaszyna::marketChart(string market,long starttime,long endtime,long interval)
{
    struct json_object *json,*jtmp2,*jtmp3;
    struct array_list *arr;
    int i;

    curl_mutex.lock();
    if (getTickerData(market+"/chartData.json?starttime="+to_stringl(starttime).toStdString()+"&endtime="+to_stringl(endtime).toStdString()+"&interval="+to_stringl(interval).toStdString(),&json))
    {
        base->swieczki.clear();
        arr=json_object_get_array(json);
        for(i=0;i<arr->length;i++)
        {
            Ohlc s;

            jtmp2=(struct json_object *)array_list_get_idx(arr,i);
            json_object_object_get_ex(jtmp2,"time",&jtmp3);
            s.t=json_object_get_int64(jtmp3);
            json_object_object_get_ex(jtmp2,"open",&jtmp3);
            s.o=json_object_get_double(jtmp3);
            json_object_object_get_ex(jtmp2,"close",&jtmp3);
            s.c=json_object_get_double(jtmp3);
            json_object_object_get_ex(jtmp2,"high",&jtmp3);
            s.h=json_object_get_double(jtmp3);
            json_object_object_get_ex(jtmp2,"low",&jtmp3);
            s.l=json_object_get_double(jtmp3);
            base->swieczki.push_back(s);
        }
        json_object_put(json);
        curl_mutex.unlock();
        return(true);
    }
    curl_mutex.unlock();
    return(false);
}
示例#9
0
文件: main.c 项目: 9re/LobiJniSample
static void handle_lobi_error(ANativeActivity *nativeActivity, int code, const char *response) {
    // see 
    // https://github.com/nakamap/docs/wiki/Android-SDK-Docs#wiki-nakamap-callback
    switch (code) {
    case LOBI_NETWORK_ERROR:
        // do something
        break;
    case LOBI_RESPONSE_ERROR:
        // do something
        break;
    case LOBI_FATAL_ERROR:
        {
            JSON_Value *responseValue = json_parse_string(response);
            JSON_Object *jsonObject = json_value_get_object(responseValue);
            // do something.
            // only in this case, response is not null and has
            // an array of messages with the key 'error'
            JSON_Array *errors = json_object_get_array((const JSON_Object *)jsonObject, "error");
            if (errors) {
                for (size_t i = 0, len = json_array_get_count(errors);
                     i < len; ++i) {
                    const char *error = json_array_get_string(errors, i);
                    lobi_showToast(nativeActivity, error);
                    LOGV("error #%d: %s", i, error);
                }
            }

            json_value_free(responseValue);
            break;
        }
    }
}
bool Bitmaszyna::lasttrades(string market)
{    
    struct json_object *json,*jtmp,*jtmp2;
    struct array_list *arr;
    int i;

    curl_mutex.lock();
    trades.clear();
    if (getTickerData(market+"/transactions.json",&json))
    {
        arr=json_object_get_array(json);
        for(i=0;i<arr->length;i++)
        {
            Offer offer;
            jtmp=(struct json_object *)array_list_get_idx(arr,i);
            json_object_object_get_ex(jtmp,"date",&jtmp2);
            offer.time=json_object_get_int64(jtmp2);
            json_object_object_get_ex(jtmp,"price",&jtmp2);
            offer.price=json_object_get_double(jtmp2);
            json_object_object_get_ex(jtmp,"amount",&jtmp2);
            offer.amount=json_object_get_double(jtmp2);
            json_object_object_get_ex(jtmp,"type",&jtmp2);
            offer.type=json_object_get_int(jtmp2);
            json_object_object_get_ex(jtmp,"type",&jtmp2);
            offer.id=json_object_get_int(jtmp2);
            trades.push_back(offer);
        }
        json_object_put(json);
        curl_mutex.unlock();
        return(true);
    }
    curl_mutex.unlock();
    return(false);
}
示例#11
0
std::vector<tagged_feedurl> ttrss_api::get_subscribed_urls() {

	std::vector<tagged_feedurl> feeds;

	struct json_object * content = run_op("getCategories", std::map<std::string, std::string>());
	if (!content)
		return feeds;

	if (json_object_get_type(content) != json_type_array)
		return feeds;

	struct array_list * categories = json_object_get_array(content);

	int catsize = array_list_length(categories);

	// first fetch feeds within no category
	fetch_feeds_per_category(NULL, feeds);

	// then fetch the feeds of all categories
	for (int i=0;i<catsize;i++) {
		struct json_object * cat = (struct json_object *)array_list_get_idx(categories, i);
		fetch_feeds_per_category(cat, feeds);
	}

	json_object_put(content);

	return feeds;
}
示例#12
0
文件: config.c 项目: indutny/bud
bud_error_t bud_config_load_backend_list(bud_config_t* config,
                                         JSON_Object* obj,
                                         bud_config_backend_list_t* backends) {
  bud_error_t err;
  JSON_Array* backend;
  int i;

  backends->external_count = 0;
  err = bud_hashmap_init(&backends->external_map, kBudBackendMapSize);
  if (!bud_is_ok(err))
    return err;

  backend = json_object_get_array(obj, "backend");
  backends->count = backend == NULL ? 0 : json_array_get_count(backend);
  backends->list = calloc(backends->count, sizeof(*backends->list));
  if (backends->list == NULL)
    return bud_error_str(kBudErrNoMem, "bud_backend_list_t");

  for (i = 0; i < backends->count; i++) {
    err = bud_config_load_backend(config,
                                  json_array_get_object(backend, i),
                                  &backends->list[i],
                                  &backends->external_map,
                                  &backends->external_count);
    if (!bud_is_ok(err))
      break;
  }
  if (!bud_is_ok(err)) {
    free(backends->list);
    backends->list = NULL;
  }
  return err;
}
示例#13
0
文件: mjson.c 项目: kingiol/cmoon
void mjson_str2hdf(HDF *node, struct json_object *o)
{
    if (!node) return;
    
    char *s = hdf_obj_value(node);
    
    struct json_object *obj;
    struct array_list *list;
    enum json_type type;
    HDF *cnode;
    char tok[64];
    int i;
    
    char *key; struct json_object *val; struct lh_entry *entry;
    
    obj = o;

    if (!obj && s && *s) {
        obj = json_tokener_parse(s);
    }
    if (!obj || obj < 0) return;

    type = json_object_get_type(obj);

    switch (type) {
    case json_type_boolean:
        hdf_set_int_value(node, NULL, json_object_get_boolean(obj));
        return;
    case json_type_int:
        hdf_set_int_value(node, NULL, json_object_get_int(obj));
        return;
    case json_type_double:
        sprintf(tok, "%f", json_object_get_double(obj));
        hdf_set_value(node, NULL, tok);
        return;
    case json_type_string:
        hdf_set_value(node, NULL, json_object_get_string(obj));
        return;
    case json_type_array:
        list = json_object_get_array(obj);
        for (i = 0; i < list->length; i++) {
            sprintf(tok, "%d", i);
            hdf_get_node(node, tok, &cnode);
            mjson_str2hdf(cnode, (struct json_object*)list->array[i]);
        }
        return;
    case json_type_object:
        for(entry = json_object_get_object(obj)->head;
            (entry ? (key = (char*)entry->k,
                      val = (struct json_object*)entry->v, entry) : 0);
            entry = entry->next) {
            hdf_get_node(node, key, &cnode);
            mjson_str2hdf(cnode, val);
        }
        return;
    default:
        return;
    }
}
示例#14
0
CJSONArrayIterator::CJSONArrayIterator(const CJSONEntry& oEntry)
{
    m_array = 0;
    m_nCurItem = 0;
    m_rootObject = 0;

    m_array = json_object_get_array( oEntry.getObject() );
}
示例#15
0
文件: u1db_query.c 项目: Kazade/Tasks
static int
extract_field_values(string_list *values, json_object *obj,
                     const string_list *field_path, int value_type)
{
    string_list_item *item = NULL;
    char string_value[MAX_INT_STR_LEN];
    struct array_list *list_val = NULL;
    json_object *val = NULL;
    int i, integer_value, boolean_value;
    int status = U1DB_OK;
    val = obj;
    if (val == NULL)
        goto finish;
    for (item = field_path->head; item != NULL; item = item->next)
    {
        val = json_object_object_get(val, item->data);
        if (val == NULL)
            goto finish;
    }
    if (json_object_is_type(val, json_type_string) && value_type ==
            json_type_string) {
        if ((status = append(values, json_object_get_string(val))) != U1DB_OK)
            goto finish;
    } else if (json_object_is_type(val, json_type_int) && value_type ==
            json_type_int) {
        integer_value = json_object_get_int(val);
        snprintf(string_value, MAX_INT_STR_LEN, "%d", integer_value);
        if (status != U1DB_OK)
            goto finish;
        if ((status = append(values, string_value)) != U1DB_OK)
            goto finish;
    } else if (json_object_is_type(val, json_type_boolean) &&
               value_type == json_type_boolean) {
        boolean_value = json_object_get_boolean(val);
        if (boolean_value) {
            status = append(values, "1");
            if (status != U1DB_OK)
                goto finish;
        } else {
            status = append(values, "0");
            if (status != U1DB_OK)
                goto finish;
        }
    } else if (json_object_is_type(val, json_type_array)) {
        // TODO: recursively check the types
        list_val = json_object_get_array(val);
        for (i = 0; i < list_val->length; i++)
        {
            if ((status = append(values, json_object_get_string(
                                array_list_get_idx(
                                    list_val, i)))) != U1DB_OK)
                goto finish;
        }
    }
finish:
    return status;
}
void CANGenPlugin::parseMappingTable(const std::string& table)
{
    scoped_lock<interprocess_recursive_mutex> lock(mutex);

    std::string json(table);
    std::replace(json.begin(), json.end(), '\'', '"');// replace all ' to "
    std::unique_ptr<json_object, decltype(&json_object_put)> rootobject(json_tokener_parse(json.c_str()), &json_object_put);
    if(!rootobject)
    {
        LOG_ERROR("Failed to parse json: " << json);
        return;
    }

    // Success, use json_obj here.
    mappingTable.clear();
    json_object *sources = json_object_object_get(rootobject.get(),"sources");
    if(!sources)
        return;
    array_list* arraySources = json_object_get_array(sources);
    if(!arraySources)
        return;
    for(int i=0; i < array_list_length(arraySources); ++i)
    {
        json_object *rootsource = static_cast<json_object*>(array_list_get_idx(arraySources,i));
        if(!rootsource)
            continue;
        json_object* source = json_object_object_get(rootsource, "source");
        if(!source)
            continue;
        json_object* guid = json_object_object_get(source, "guid");
        const std::string guidstr(guid ? json_object_get_string(guid) : "");
        json_object* signals = json_object_object_get(rootsource, "signals");
        if(!signals)
            continue;
        array_list* arraySignals = json_object_get_array(signals);
        for(int j = 0; j < array_list_length(arraySignals); ++j)
        {
            json_object *signal = static_cast<json_object*>(array_list_get_idx(arraySignals,j));
            if(!signal)
                continue;
            mappingTable.addProperty(guidstr, signal);
        }// signals array loop
    }// sources array loop
}
示例#17
0
std::map<std::string, std::vector<std::string>> newsblur_api::mk_feeds_to_tags(
json_object * folders)
{
	std::map<std::string, std::vector<std::string>> result;
	array_list * tags = json_object_get_array(folders);
	int tags_len = array_list_length(tags);
	for (int i = 0; i < tags_len; ++i) {
		json_object * tag_to_feed_ids = json_object_array_get_idx(folders, i);
		json_object_object_foreach(tag_to_feed_ids, key, feeds_with_tag_obj) {
			std::string std_key(key);
			array_list * feeds_with_tag_arr = json_object_get_array(feeds_with_tag_obj);
			int feeds_with_tag_len = array_list_length(feeds_with_tag_arr);
			for (int j = 0; j < feeds_with_tag_len; ++j) {
				json_object * feed_id_obj = json_object_array_get_idx(feeds_with_tag_obj, j);
				std::string feed_id(json_object_get_string(feed_id_obj));
				result[feed_id].push_back(std_key);
			}
		}
	}
示例#18
0
void ttrss_api::fetch_feeds_per_category(struct json_object * cat, std::vector<tagged_feedurl>& feeds) {
	const char * cat_name = NULL;
	struct json_object * cat_title_obj = NULL;
	int cat_id;

	if (cat) {
		struct json_object * cat_id_obj = json_object_object_get(cat, "id");
		cat_id = json_object_get_int(cat_id_obj);

		// ignore special categories, for now
		if(cat_id < 0)
			return;

		cat_title_obj = json_object_object_get(cat, "title");
		cat_name = json_object_get_string(cat_title_obj);
		LOG(LOG_DEBUG, "ttrss_api::fetch_feeds_per_category: id = %d title = %s", cat_id, cat_name);
	}
	else {
		// As uncategorized is a category itself (id = 0) and the default value
		// for a getFeeds is id = 0, the feeds in uncategorized will appear twice
		return;
	}

	std::map<std::string, std::string> args;
	if (cat)
		args["cat_id"] = utils::to_string<int>(cat_id);
	struct json_object * feed_list_obj = run_op("getFeeds", args);

	if (!feed_list_obj)
		return;

	struct array_list * feed_list = json_object_get_array(feed_list_obj);

	int feed_list_size = array_list_length(feed_list);

	for (int j=0;j<feed_list_size;j++) {
		struct json_object * feed = (struct json_object *)array_list_get_idx(feed_list, j);

		int feed_id = json_object_get_int(json_object_object_get(feed, "id"));
		const char * feed_title = json_object_get_string(json_object_object_get(feed, "title"));
		const char * feed_url = json_object_get_string(json_object_object_get(feed, "feed_url"));

		std::vector<std::string> tags;
		tags.push_back(std::string("~") + feed_title);
		if (cat_name) {
			tags.push_back(cat_name);
		}
		feeds.push_back(tagged_feedurl(utils::strprintf("%s#%d", feed_url, feed_id), tags));

		// TODO: cache feed_id -> feed_url (or feed_url -> feed_id ?)
	}

	json_object_put(feed_list_obj);

}
示例#19
0
文件: tests.c 项目: Kutoc/parson
void test_suite_5(void) {
    JSON_Value *val_from_file = json_parse_file("tests/test_5.txt");
    
    JSON_Value *val = json_value_init_object();
    JSON_Object *obj = json_value_get_object(val);
    TEST(json_object_set_string(obj, "first", "John") == JSONSuccess);
    TEST(json_object_set_string(obj, "last", "Doe") == JSONSuccess);
    TEST(json_object_set_number(obj, "age", 25) == JSONSuccess);
    TEST(json_object_set_boolean(obj, "registered", 1) == JSONSuccess);
    TEST(json_object_set_value(obj, "interests", json_value_init_array()) == JSONSuccess);
    TEST(json_array_append_string(json_object_get_array(obj, "interests"), "Writing") == JSONSuccess);
    TEST(json_array_append_string(json_object_get_array(obj, "interests"), "Mountain Biking") == JSONSuccess);
    TEST(json_array_replace_string(json_object_get_array(obj, "interests"), 0, "Reading") == JSONSuccess);
    TEST(json_object_dotset_string(obj, "favorites.color", "blue") == JSONSuccess);
    TEST(json_object_dotset_string(obj, "favorites.sport", "running") == JSONSuccess);
    TEST(json_object_dotset_string(obj, "favorites.fruit", "apple") == JSONSuccess);
    TEST(json_object_dotremove(obj, "favorites.fruit") == JSONSuccess);
    TEST(json_object_set_string(obj, "utf string", "\\u006corem\\u0020ipsum") == JSONSuccess);
    TEST(json_object_set_string(obj, "utf-8 string", "あいうえお") == JSONSuccess);
    TEST(json_object_set_string(obj, "surrogate string", "lorem\\uD834\\uDD1Eipsum\\uD834\\uDF67lorem") == JSONSuccess);
    TEST(json_value_equals(val_from_file, val));
}
示例#20
0
文件: tests.c 项目: Kutoc/parson
void test_suite_6(void) {
    const char *filename = "tests/test_2.txt";
    JSON_Value *a = NULL;
    JSON_Value *b = NULL;
    a = json_parse_file(filename);
    b = json_parse_file(filename);
    TEST(json_value_equals(a, b));
    json_object_set_string(json_object(a), "string", "eki");
    TEST(!json_value_equals(a, b));
    a = json_value_deep_copy(b);
    TEST(json_value_equals(a, b));
    json_array_append_number(json_object_get_array(json_object(b), "string array"), 1337);
    TEST(!json_value_equals(a, b));
}
示例#21
0
文件: read_feeds.c 项目: JBTech/m2x-c
int main()
{
  m2x_context *ctx = NULL;
  JSON_Value *val = NULL;
  JSON_Array *feeds = NULL;
  size_t i;

  ctx = m2x_open(M2X_KEY);
  if (m2x_json_feed_list(ctx, "", &val) == 0) {
    feeds = json_object_get_array(json_value_get_object(val), "feeds");
    for (i = 0; i < json_array_get_count(feeds); i++) {
      JSON_Object* feed = json_array_get_object(feeds, i);
      printf("Feed id: %s\n", json_object_get_string(feed, "id"));

      printf("   name: %s\n", json_object_get_string(feed, "name"));
      printf("Contains %ld streams\n\n",
             json_array_get_count(json_object_get_array(feed, "streams")));
    }
    json_value_free(val);
  }
  m2x_close(ctx);
  return 0;
}
示例#22
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) {
                array_list *res = json_object_get_array(poResults);
                if(res != nullptr) {
                    CPLprintf("List of available datasets for project id: %s\n", GetProjectId());
                    CPLprintf("| id \t | name\n");
                    CPLprintf("|--------|-------------------\n");
                    for(decltype(res->length) i = 0; i < res->length; i++) {
                        json_object *ds = (json_object*)array_list_get_idx(res, 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;
}
示例#23
0
文件: mbson.c 项目: pombredanne/cmoon
static void json_append_to_bson(bson* b, char *key, struct json_object *val)
{
    if (!b || !key || !val) return;

    struct array_list *list;
    enum json_type type;
    bson *sub;
    char tok[64];

    type = json_object_get_type(val);

    switch (type) {
    case json_type_boolean:
        bson_append_boolean(b, key, json_object_get_boolean(val));
        break;
    case json_type_int:
        bson_append_int32(b, key, json_object_get_int(val));
        break;
    case json_type_double:
        bson_append_double(b, key, json_object_get_double(val));
        break;
    case json_type_string:
        bson_append_string(b, key, json_object_get_string(val), -1);
        break;
    case json_type_array:
        sub = bson_new();

        list = json_object_get_array(val);
        for (int pos = 0; pos < list->length; pos++) {
            sprintf(tok, "%d", pos);
            json_append_to_bson(sub, tok, (struct json_object*)list->array[pos]);
        }
        
        bson_finish(sub);
        bson_append_array(b, key, sub);
        bson_free(sub);
        break;
    case json_type_object:
        sub = mbson_new_from_jsonobj(val, true, false);
        bson_append_document(b, key, sub);
        bson_free(sub);
        break;
    default:
        break;
    }
    
    
}
示例#24
0
bud_error_t bud_config_load_frontend(JSON_Object* obj,
                                     bud_config_frontend_t* frontend) {
  bud_error_t err;
  JSON_Value* val;

  bud_config_load_addr(obj, (bud_config_addr_t*) frontend);

  frontend->server_preference = -1;
  frontend->ssl3 = -1;
  frontend->max_send_fragment = -1;
  frontend->allow_half_open = -1;
  if (obj == NULL)
    return bud_ok();

  frontend->security = json_object_get_string(obj, "security");
  frontend->ciphers = json_object_get_string(obj, "ciphers");
  frontend->ecdh = json_object_get_string(obj, "ecdh");
  frontend->cert_file = json_object_get_string(obj, "cert");
  frontend->key_file = json_object_get_string(obj, "key");
  frontend->reneg_window = json_object_get_number(obj, "reneg_window");
  frontend->reneg_limit = json_object_get_number(obj, "reneg_limit");
  frontend->ticket_key = json_object_get_string(obj, "ticket_key");

  /* Get and verify NPN */
  frontend->npn = json_object_get_array(obj, "npn");
  err = bud_config_verify_npn(frontend->npn);
  if (!bud_is_ok(err))
    goto fatal;

  val = json_object_get_value(obj, "server_preference");
  if (val != NULL)
    frontend->server_preference = json_value_get_boolean(val);
  val = json_object_get_value(obj, "ssl3");
  if (val != NULL)
    frontend->ssl3 = json_value_get_boolean(val);
  val = json_object_get_value(obj, "max_send_fragment");
  if (val != NULL)
    frontend->max_send_fragment = json_value_get_number(val);
  val = json_object_get_value(obj, "allow_half_open");
  if (val != NULL)
    frontend->allow_half_open = json_value_get_boolean(val);

fatal:
  return err;
}
示例#25
0
文件: config.c 项目: indutny/bud
bud_error_t bud_config_load_frontend_ifaces(
    JSON_Object* obj,
    bud_config_frontend_interface_t* interface) {
  JSON_Array* arr;
  int i;

  arr = json_object_get_array(obj, "interfaces");
  interface->count = arr == NULL ? 0 : json_array_get_count(arr);
  if (interface->count == 0)
    return bud_ok();

  interface->list = calloc(interface->count, sizeof(*interface->list));
  if (interface->list == NULL)
    return bud_error_str(kBudErrNoMem, "bud_frontend_interface_t");

  for (i = 0; i < interface->count; i++)
    bud_config_load_addr(json_array_get_object(arr, i), &interface->list[i]);

  return bud_ok();
}
示例#26
0
int n_json_del_element_from_array_by_idx( struct json_object * obj, int idx )
{
    int     i;  
    struct array_list *arr;

    if ( !json_object_is_type( obj , JSON_TYPE_ARRAY ) ) 
        return -1; 

    if ( idx >= json_object_array_length( obj ) ) 
        return -1; 

    arr = json_object_get_array( obj );  
    json_object_put( json_object_array_get_idx( obj , idx ) );

    for ( i = idx; i < arr->length - 1; i++ )
        arr->array[i] = arr->array[i+1];
    arr->length--;

    return 0;   
}
示例#27
0
文件: rpc.c 项目: lynnard/RPC
int read_channels_json(json_object *obj, fm_channel_t **channels, int *number) {
    int ret = -1;
    int i;
    if (obj) {
        array_list *channel_objs = json_object_get_array(json_object_object_get(obj, "channels"));
        if (channel_objs) {
            *number = array_list_length(channel_objs);
            *channels = (fm_channel_t *) malloc(*number * sizeof(fm_channel_t));
            for (i = 0; i < *number; i++) {
                json_object *o = (json_object*) array_list_get_idx(channel_objs, i);
                int id = json_object_get_int(json_object_object_get(o, "channel_id"));
                (*channels)[i].id = id;
                (*channels)[i].name = strdup(json_object_get_string(json_object_object_get(o, "name")));
            }
            ret = 0;
        }
        json_object_put(obj);
    }
    return ret;
}
void DatabaseSink::parseConfig()
{
	json_object *rootobject;
	json_tokener *tokener = json_tokener_new();
	enum json_tokener_error err;
	do
	{
		rootobject = json_tokener_parse_ex(tokener, configuration["properties"].c_str(),configuration["properties"].size());
	} while ((err = json_tokener_get_error(tokener)) == json_tokener_continue);
	if (err != json_tokener_success)
	{
		fprintf(stderr, "Error: %s\n", json_tokener_error_desc(err));
	}
	if (tokener->char_offset < configuration["properties"].size()) // XXX shouldn't access internal fields
	{
		//Should handle the extra data here sometime...
	}
	
	json_object *propobject = json_object_object_get(rootobject,"properties");
	
	g_assert(json_object_get_type(propobject) == json_type_array);

	array_list *proplist = json_object_get_array(propobject);
	
 	for(int i=0; i < array_list_length(proplist); i++)
	{
		json_object *idxobj = (json_object*)array_list_get_idx(proplist,i);
		std::string prop = json_object_get_string(idxobj);
		propertiesToSubscribeTo.push_back(prop);

		DebugOut()<<"DatabaseSink logging: "<<prop<<endl;
	}

	json_object_put(propobject);
	json_object_put(rootobject);
}
bool Bitmaszyna::getopenorders(string)
{
    struct json_object *json,*jtmp;
    struct array_list *arr;
    int i;
    Offer o;

    curl_mutex.lock();
    orders.clear();
    if (makeApiCall("offers",&json,string("nonce=")+to_stringl(getctime()).toStdString()))
    {
        if (!fetchData(&json,&jtmp)) return(false);
        json_object_object_get_ex(json,"orders",&jtmp);
        arr=json_object_get_array(jtmp);
        for(i=0;i<arr->length;i++)
        {
            struct json_object *jtmp3,*jtmp4;

            jtmp3=(struct json_object *)array_list_get_idx(arr,i);
            json_object_object_get_ex(jtmp3,"id",&jtmp4);
            o.id=to_stringl(json_object_get_int(jtmp4)).toStdString();
            json_object_object_get_ex(jtmp3,"price",&jtmp4);
            o.price=json_object_get_double(jtmp4);
            json_object_object_get_ex(jtmp3,"amount",&jtmp4);
            o.amount=json_object_get_double(jtmp4);
            json_object_object_get_ex(jtmp3,"type",&jtmp4);
            o.type=json_object_get_double(jtmp4);
            orders.push_back(o);
        }
        json_object_put(json);
        curl_mutex.unlock();
        return(true);
    }
    curl_mutex.unlock();
    return(false);
}
示例#30
0
/*
*打印JSON object类型的值
*返回类型: none
*返回值: none
*传入参数json_object *类型
*author  mleaf_hexi
*mail:[email protected]
*/ 
static void json_print_object(json_object *obj) 
{
	char *configData="configData";
	char *requestId="requestId";
	
	char *delim=":/,";//分割字符串
	char *p;
	char *s;
	char *name,*value,*next,*value1,*next1,*next2;
	int i;
	char buff[50],buff2[50];
	if(!obj) return;
	//遍历json对象的key和值 
	//Linux内核2.6.29,说明了strtok()已经不再使用,由速度更快的strsep()代替。
	json_object_object_foreach(obj,key,val) 
	{
		//printf("%s => ",key);
		if(strcmp(key,configData)==0)//取出通讯用url
		{
			printf("configData checking out\n");
			printf("configData=%s\n",json_object_get_string(val));
			
			s=(char*)json_object_get_string(val);
			printf("%s\n",s);
//wss: //area1.dts.mpush.brxy-cloud.com/websocket/connHandler/v2.0,wss: //primary.dts.mpush.brxy-cloud.com/websocket/connHandler/v2.0
			
			value = strdup(s);

			for(i=0 ;i<2 ;i++)
			{ // 第一次执行时
				name = strsep(&value,":"); // 以":"分割字符串,这时strsep函数返回值为 "wss",即":"号之前的字符串
				next =value; // 这时指针value指向":"号后面的字符串,即 //area1.dts.mpush.brxy-cloud.com/websocket/connHandler/v2.0,wss: //primary.dts.mpush.brxy-cloud.com/websocket/connHandler/v2.0
				printf(" name= %s\n",name); //打印出一轮分割后name的值
				name = strsep(&value,"/");// 这时通过"/"分割字符串
				next =value; 
				name = strsep(&value,"/");//去掉第二个/
				next =value; 
				if(i==0)
				{
					value=strsep(&next,",");// 以","分割字符串,这时strsep函数返回值为 "area1.dts.mpush.brxy-cloud.com/websocket/connHandler/v2.0",即","号之前的字符串
					printf("value= %s\n",value);
					next2 =value;
					value=strsep(&next2,"/");
					printf("value= %s\n",value);//area1.dts.mpush.brxy-cloud.com
					sprintf(buff2,"/%s",next2);
					printf("next2= %s\n",buff2);/* /websocket/connHandler/v2.0	 */ 
				}
				if(i==1)//第二轮循环
				{
					value1=strsep(&next,"");// 以/0分割字符串,这时strsep函数返回值为 "primary.dts.mpush.brxy-cloud.com/websocket/connHandler/v2.0",即wss: //之后"/0"之前的字符串
					printf("value1= %s\n",value1);
					next1 =value1;
					value1=strsep(&next1,"/");
					printf("value2= %s\n",value1);//primary.dts.mpush.brxy-cloud.com
					sprintf(buff,"/%s",next1);
					printf("next1= %s\n",buff);/* /websocket/connHandler/v2.0  */

				}
				value=next;
			}
//			char *source = strdup(s); 
//			char *token;  
//			for(token = strsep(&source, delim); token != NULL; token = strsep(&source, delim)) 
//			{  
//				printf("%s",token);  
//				printf("\n");  
//			}
		}
		else if (strcmp(key,requestId) == 0)//取出requestId 号	
		{
				array_list* arr = json_object_get_array(val);
				json_object* obj = (json_object*)array_list_get_idx(arr,0);
				printf("requestId checking out\n");
				printf("requestId=%s\n", json_object_get_string(obj));
		}
	
		json_print_value(val);
	}
}