#include "HelloWorldScene.h"
Scene* HelloWorld::createScene()
auto scene = Scene::create();
auto layer = HelloWorld::create();
// on "init" you need to initialize your instance
if ( !Layer::init() ) return false;
std::vector<std::string> headers;
headers.push_back("Content-Type: application/json; charset=utf-8");
HttpRequest *request = new HttpRequest();
request->setUrl("http://domain.net/*****"); //URLは自分の環境にあわせてください
request->setRequestType(HttpRequest::Type::GET);
auto ad = &HelloWorld::onHttpRequestCallBack;
request->setResponseCallback(this, SEL_HttpResponse(ad));
request->setHeaders(headers);
HttpClient::getInstance()->send(request);
void HelloWorld::onHttpRequestCallBack(HttpClient* sender, HttpResponse* response)
picojson::value response_data;
CCASSERT(response, "response empty");
CCASSERT(response->isSucceed(), "response failed");
std::vector<char>* buffer = response->getResponseData();
char * json = (char *) malloc(buffer->size() + 1);
std::string s2(buffer->begin(), buffer->end());
strcpy(json, s2.c_str());
picojson::parse(response_data, json, json + strlen(json), &err);
CCASSERT(err.empty(), err.c_str());
picojson::object& values = response_data.get<picojson::object>();
auto id = Value(values["id"].get<double>());
auto title = Value(values["title"].get<std::string>());
CCLOG("%s", title.asString().c_str());
auto is_bool = Value(values["is_bool"].get<bool>());
CCLOG("%s", is_bool.asString().c_str());