Jansson is a C JSON library which doesn't depend on other libraries, so if like me you need something to run on Android's NDK which doesn't support STL, you want to be using this.
http://www.digip.org/jansson/
Since I find sample code to be the easiest way of picking up a new library..
Here is example code showing you how to parse your friends list from Facebook's graph api using lib_json.
#include "json.h"
...
std::string jsonResponse( reply->data.buffer );
Json::Value root;
Json::Reader reader;
const BOOL parsingSuccessful = reader.parse( jsonResponse, root );
ASSERT( parsingSuccessful );
if( parsingSuccessful )
{
const Json::Value jsonData = root["data"];
const uint length = jsonData.size();
for( uint i=0; i<length; ++i )
{
Json::Value text = jsonData[i];
std::string jsonStringName = text["name"].asString();
std::string jsonStringID = text["id"].asString();
// We can now do something with our Name and ID
}
}
Here is example code showing you how to parse your friends list from Facebook's graph api Jansson.
#include "jansson.h"
...
json_error_t error;
json_t *root = json_loads( reply->data.buffer, 0, &error );
if( root )
{
json_t *jsonData = json_object_get( root, "data" );
if( json_is_array( jsonData ) )
{
const uint length = json_array_size( jsonData );
for( uint i=0; i<length; ++i ) // Iterates over the sequence elements.
{
json_t *jsonObject = json_array_get( jsonData, i );
json_t *jsonID = json_object_get( jsonObject, "id" );
const char *jsonStringID = json_string_value( jsonID );
json_t *jsonName = json_object_get( jsonObject, "name" );
const char *jsonStringName = json_string_value( jsonName );
// We can now do something with our Name and ID
}
}
json_decref( root );
}
i'm finding the JSON libraries that are available for Java on Android to be quite slow. is there anyway you can provide benchmarks that compare org.json, gson and jackson with your jannson impl? before i dive into the ndk i'd just like to make sure there's a tangible (and suitably substantial) performance difference. here's what i've found with gson/jackson:
ReplyDelete////////Gson
parse records: 62
parse time in ms: 16837
///////Jackson
parse records: 62
parse time in ms: 12851
if you could provide any comparison between either gson/jackson with jannson that would be an enormous help.