예제 #1
0
int json_to_bson_append_array( bson *bb , struct json_object *a )
{
	int i,al_len;
	char *al;
	json_object *it;

	for ( i=0; i<json_object_array_length( a ); i++ ) {
		al = int2str(i,&al_len);
		if (al == NULL) {
			LM_ERR("Failed to convert %d to str\n",i);
			return -1;
		}

		al[al_len]=0;
		it = json_object_array_get_idx(a,i);
		if (it == NULL) {
			LM_ERR("Failed to get JSON idx\n");
			return -1;
		}

		if (json_to_bson_append_element(bb,al,it) < 0) {
			LM_ERR("Failed to append element to BSON\n");
			return -1;
		}
    }

	return 0;
}
예제 #2
0
/**
   should already have called start_array
   this will not call start/finish
 */
void json_to_bson_append_array( bson_buffer * bb , struct json_object * a ){
    int i;
    char buf[10];
    for ( i=0; i<json_object_array_length( a ); i++){
        sprintf( buf , "%d" , i );
        json_to_bson_append_element( bb , buf , json_object_array_get_idx( a , i ) );
    }
}
예제 #3
0
	json_object_object_iterator( o,key,val ) {
		if (json_to_bson_append_element(bb,key,val)<0) {
			LM_ERR("Failed to append new element\n");
			return -1;
		}
	}
예제 #4
0
 json_object_object_foreach(o,k,v){
     json_to_bson_append_element( bb , k , v );
 }