Skip to content

Instantly share code, notes, and snippets.

@gregkepler
Created July 4, 2013 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregkepler/5924035 to your computer and use it in GitHub Desktop.
Save gregkepler/5924035 to your computer and use it in GitHub Desktop.
Cinder app to demonstrate how the app crashes when run on iOS when it parses a json file containing a float.
#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include "cinder/Json.h"
using namespace ci;
using namespace ci::app;
using namespace std;
JsonTree queryData( const std::string &query );
class JsonIosApp : public AppNative {
public:
void setup();
void update();
void draw();
void loadJson();
bool mDataRetrieved = false;
JsonTree mData;
};
void JsonIosApp::setup()
{
/*string num = "0.41999999999999998";
//string newString = boost::lexical_cast<string>( num );
Json::Value newString = Json::Value( fromString<double>( num ) );
console() << newString << endl;*/
}
void JsonIosApp::loadJson()
{
JsonTree searchResults;
JsonTree queryResult;
while( ! mDataRetrieved ) {
try {
mData = queryData("sampleData.json");
console() << queryResult << endl;
// searchResults = queryResult.getChild("daily");
mDataRetrieved = true;
}
catch (const std::exception& ex) {
console() << "exception" << endl;
console() << ex.what() << endl;
ci::sleep( 1000 ); // try again in 1 second
}
}
}
void JsonIosApp::update()
{
if(!mDataRetrieved){
loadJson();
}
}
void JsonIosApp::draw()
{
// clear out the window with black
gl::clear( Color( 0, 0, 0 ) );
}
JsonTree queryData( const std::string &searchUrl )
{
Url url(searchUrl , true );
// DataSourceRef dataSource = loadUrl( url );
DataSourceRef dataSource = loadResource( searchUrl );
string dataString = loadString( dataSource );
JsonTree data = JsonTree( dataString );
//console() << "DATA string: " << dataString << endl;
//console() << data.getChild("daily") << endl;
return data;
}
CINDER_APP_NATIVE( JsonIosApp, RendererGl )
{
"daily":{
"data":[
{
"time":1372478400,
"summary":"Partly cloudy until evening.",
"icon":"partly-cloudy-day",
"sunriseTime":1372498151,
"sunsetTime":1372552419,
"precipIntensity":0.003,
"precipIntensityMax":0.013,
"precipIntensityMaxTime":1372478400,
"precipType":"rain",
"temperatureMin":68.43,
"temperatureMinTime":1372500000,
"temperatureMax":84.69,
"temperatureMaxTime":1372536000,
"dewPoint":67.21,
"windSpeed":6.32,
"windBearing":200,
"cloudCover":0.42,
"humidity":0.74,
"pressure":1002,
"visibility":10,
"ozone":324.98
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment