コード例 #1
0
ファイル: node-print.c プロジェクト: argasek/morphine
void JsonPrint(JsonNodeT *node, int indent) {
  int i;

  switch (node->type) {
    case JSON_NULL:
      printf("null");
      break;
    case JSON_BOOLEAN:
      printf(node->u.boolean ? "true" : "false");
      break;
    case JSON_INTEGER:
      printf("%ld", node->u.integer);
      break;
    case JSON_REAL:
      printf("%f", node->u.real);
      break;
    case JSON_STRING:
      printf("\"%s\"", node->u.string);
      break;
    case JSON_ARRAY:
      putchar('[');
      if (node->u.array.num)
        putchar('\n');
      for (i = 0; i < node->u.array.num; i++) {
        JsonPrint(node->u.array.item[i], indent + 2);
        if (i < node->u.array.num - 1)
          puts(",");
        else
          putchar('\n');
      }
      if (node->u.array.num)
        PrintSpaces(indent);
      putchar(']');
      break;
    case JSON_OBJECT:
      PrintSpaces(indent);
      putchar('{');
      if (node->u.object.num)
        putchar('\n');
      for (i = 0; i < node->u.object.num; i++) {
        PrintSpaces(indent + 1);
        printf("%s : ", node->u.object.item[i].key);
        JsonPrint(node->u.object.item[i].value, indent + 2);
        if (i < node->u.object.num - 1)
          puts(",");
        else
          putchar('\n');
      }
      if (node->u.object.num)
        PrintSpaces(indent);
      putchar('}');
      break;
  }
}
コード例 #2
0
ファイル: exp_led.cpp プロジェクト: OnionIoT/ubus-intf
int ExpLed::_FunctionStatus (void)
{
	int 	status 	= EXIT_SUCCESS;

	int 	colorVals[EXP_LED_COLOR_ID_NUM];


	// read the GPIO values
	status |= 	gpioObj.Read(pins[EXP_LED_COLOR_ID_R], colorVals[EXP_LED_COLOR_ID_R] );
	status |= 	gpioObj.Read(pins[EXP_LED_COLOR_ID_G], colorVals[EXP_LED_COLOR_ID_G] );
	status |= 	gpioObj.Read(pins[EXP_LED_COLOR_ID_B], colorVals[EXP_LED_COLOR_ID_B] );


	// setup the json object
	jsonOut.SetObject();

	// write the values to the json
	_GenerateJsonMember( EXP_LED_COLOR_R_STRING, !colorVals[EXP_LED_COLOR_ID_R] );
	_GenerateJsonMember( EXP_LED_COLOR_G_STRING, !colorVals[EXP_LED_COLOR_ID_G] );
	_GenerateJsonMember( EXP_LED_COLOR_B_STRING, !colorVals[EXP_LED_COLOR_ID_B] );

	// output the json object
	JsonPrint();


	return (status);
}
コード例 #3
0
ファイル: exp_led.cpp プロジェクト: OnionIoT/ubus-intf
//// json functions
void ExpLed::_GenerateOutJson (int inputStatus)
{
	rapidjson::Value 	element;


	// setup the json object
	jsonOut.SetObject();

	// populate the value
	if (inputStatus == EXIT_SUCCESS)
	{
		element.SetString("true");
	}
	else {
		element.SetString("false");
	}

	// add element to the json object
	jsonOut.AddMember("success", element, jsonOut.GetAllocator() );

	// output the json object
	JsonPrint();
}