int main(void)
{
	WDT_DISABLE; 
	BC1MSET;
	
  	USCIAB0RX_ISR_callbacks = rx_callbacks;
	
	uart_init(UART0, 1000000, 9600);
	uart_XLED_enable(UART0);
	uart_interrupt_enable(UART0);
	
	P1DIR &= ~BUTTON;
	P1REN |= BUTTON;
	P1OUT |= BUTTON;
	
	qputs(UART0, "Inited.\n");
	
	
	json_handle a;
	while (1){
 		p = text;
 		wait = 1;
 		_BIS_SR(CPUOFF + GIE);
 		wait = 0;
 		*p = '\0';
		
 		if (P1IN & BUTTON) {// Key not pressed
			a = objTest();
		}
		else {
			pos = 0;
			a = json_createObjectObj("root", json_createStringObj("response","cleared"), NULL);
		}
 
 		json_dump(text, a);
  		json_free_rude(a);
		
		
// 		int i;
// 		qputh(_uart1, 0xff & (pos >> 8));
// 		qputh(_uart1, 0xff & (pos));
// 		qputc(_uart1,'\n');
// 		for (i=0;i<PERIOD_LENGTH/2;i++){
// 			
// 			//qputs(_uart1, " 0x");
// 			qputh(_uart1, 0xff & (data[pos+i] >> 8));
// 			qputh(_uart1, 0xff & data[pos+i]);
// 		}
// 		qputs(_uart1, "\n============\n");
// 		base64enc(text, &data[pos], PERIOD_LENGTH);
		
		
  		qputs(UART0, text);
		qputc(UART0, '\n');
		//__delay_cycles(800000);
		
		
	}
	
}
Beispiel #2
0
int main( int argc, char const * const *argv )
{
  json_t *json;
  int ret;
  apr_status_t status;
  apr_pool_t *mp;
  apr_file_t *xml_fp;
  apr_file_t *out_fp;
  const char *xml_file;
  const char *out_file;
  int preserve_root;
  int indent;

  apr_app_initialize( NULL, NULL, NULL );
  apr_pool_create( &mp, NULL );

  xml2json_init( argc, argv, mp, &xml_file, &out_file, &preserve_root,
                 &indent );

  if ( open_apr_input_file( mp, xml_file, &xml_fp ) &&
       open_apr_output_file( mp, out_file, &out_fp ) &&
       xml_to_json( mp, xml_fp, !preserve_root, &json ) ) {
    json_dump( out_fp, json, indent );
    ret = 0;
  }
  else {
    fprintf( stderr, "failed to convert\n" );
    ret = 1;
  }

  apr_pool_destroy( mp );
  apr_terminate();

  return ret;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
	JSON *j;
	if(argc < 2) 
		return EXIT_FAILURE;
	j = json_read(argv[1]);
	if(!j) {
		json_error("Unable to parse %s", argv[1]);
		return EXIT_FAILURE;
	} else {
		json_dump(j);
		json_free(j);
		return EXIT_SUCCESS;
	}
}
Beispiel #4
0
static struct json *foo(struct jrpc_context * ctx, struct json *params,
			      struct json *id)
{
	struct json *reply, *item, *array;
	int a, b, i;
	char buf[1024];

	json_dump(params);
	json_dump(id);

	item = json_get_object_item(params->child, "A");
	a = item->valueint;

	item = json_get_object_item(params->child, "B");
	b = item->valueint;

	sprintf(buf, "recv a:%d b:%d", a, b);

	array = json_create_array();

	for(i = 0; i < a; i ++){
		item = json_create_object();
		json_add_number_to_object(item, "A", i);
		json_add_number_to_object(item, "B", b++);
		json_add_item_to_array(array, item);
	}




	reply = json_create_object();
	json_add_item_to_object(reply, "Args", array);
	json_add_string_to_object(reply, "Str", buf);
	json_dump(reply);

	return reply;
}
Beispiel #5
0
static SLVAL
sl_json_dump(sl_vm_t* vm, SLVAL self, SLVAL object)
{
    json_dump_t dump;
    dump.vm = vm;
    dump.buffer_len = 0;
    dump.buffer_cap = 32;
    dump.buffer = sl_alloc_buffer(vm->arena, dump.buffer_cap);
    dump.seen_len = 0;
    dump.seen_cap = 32;
    dump.seen_ptrs = sl_alloc(vm->arena, sizeof(void*) * dump.seen_cap);
    json_dump(&dump, object);
    return sl_make_string(vm, dump.buffer, dump.buffer_len);
    (void)self;
}
Beispiel #6
0
static void
json_dump(json_dump_t* state, SLVAL object)
{
    sl_string_t* str;
    size_t i, len;
    SLVAL* keys;
    switch(sl_get_primitive_type(object)) {
        case SL_T_NIL:
            JSON_DUMP_NEED_BYTES(4);
            memcpy(state->buffer + state->buffer_len, "null", 4);
            state->buffer_len += 4;
            break;
        case SL_T_TRUE:
            JSON_DUMP_NEED_BYTES(4);
            memcpy(state->buffer + state->buffer_len, "true", 4);
            state->buffer_len += 4;
            break;
        case SL_T_FALSE:
            JSON_DUMP_NEED_BYTES(5);
            memcpy(state->buffer + state->buffer_len, "false", 5);
            state->buffer_len += 5;
            break;
        case SL_T_INT:
            str = (sl_string_t*)sl_get_ptr(sl_int_to_s(state->vm, object));
            JSON_DUMP_NEED_BYTES(str->buff_len);
            memcpy(state->buffer + state->buffer_len, str->buff, str->buff_len);
            state->buffer_len += str->buff_len;
            break;
        case SL_T_FLOAT:
            str = (sl_string_t*)sl_get_ptr(sl_float_to_s(state->vm, object));
            JSON_DUMP_NEED_BYTES(str->buff_len);
            memcpy(state->buffer + state->buffer_len, str->buff, str->buff_len);
            state->buffer_len += str->buff_len;
            break;
        case SL_T_BIGNUM:
            str = (sl_string_t*)sl_get_ptr(sl_bignum_to_s(state->vm, object));
            JSON_DUMP_NEED_BYTES(str->buff_len);
            memcpy(state->buffer + state->buffer_len, str->buff, str->buff_len);
            state->buffer_len += str->buff_len;
            break;
        case SL_T_STRING:
            str = (sl_string_t*)sl_get_ptr(sl_string_inspect(state->vm, object));
            JSON_DUMP_NEED_BYTES(str->buff_len);
            memcpy(state->buffer + state->buffer_len, str->buff, str->buff_len);
            state->buffer_len += str->buff_len;
            break;
        case SL_T_ARRAY:
            JSON_CHECK_RECURSION(object);
            JSON_DUMP_NEED_BYTES(1);
            state->buffer[state->buffer_len++] = '[';
            len = sl_get_int(sl_array_length(state->vm, object));
            for(i = 0; i < len; i++) {
                if(i) {
                    JSON_DUMP_NEED_BYTES(1);
                    state->buffer[state->buffer_len++] = ',';
                }
                json_dump(state, sl_array_get(state->vm, object, i));
            }
            JSON_DUMP_NEED_BYTES(1);
            state->buffer[state->buffer_len++] = ']';
            JSON_END_CHECK_RECURSION();
            break;
        case SL_T_DICT:
            JSON_CHECK_RECURSION(object);
            JSON_DUMP_NEED_BYTES(1);
            state->buffer[state->buffer_len++] = '{';
            keys = sl_dict_keys(state->vm, object, &len);
            for(i = 0; i < len; i++) {
                if(i) {
                    JSON_DUMP_NEED_BYTES(1);
                    state->buffer[state->buffer_len++] = ',';
                }
                json_dump(state, sl_to_s(state->vm, keys[i]));
                JSON_DUMP_NEED_BYTES(1);
                state->buffer[state->buffer_len++] = ':';
                json_dump(state, sl_dict_get(state->vm, object, keys[i]));
            }
            JSON_DUMP_NEED_BYTES(1);
            state->buffer[state->buffer_len++] = '}';
            JSON_END_CHECK_RECURSION();
            break;
        default:
            if(!sl_responds_to(state->vm, object, "to_json")) {
                SLVAL DumpError = state->vm->store[cJSON_DumpError];
                sl_error(state->vm, DumpError, "Can't convert type %V to JSON. You can implement #to_json to fix this.", sl_class_of(state->vm, object));
            }
            str = (sl_string_t*)sl_get_ptr(sl_to_s(state->vm, sl_send(state->vm, object, "to_json", 0, NULL)));
            JSON_DUMP_NEED_BYTES(str->buff_len);
            memcpy(state->buffer + state->buffer_len, str->buff, str->buff_len);
            state->buffer_len += str->buff_len;
            break;
    }
}