Hey guys, I want to parse JSON in C++-land. The best way I could come up 
with is like this. I'm wondering if this is especially inefficient or if 
it's looking good. Also, since it works I figure it will be useful to share 
in case it hasn't been yet.

using v8; // Of course...
Handle<Object> parseJson(Handle<Value> jsonString) {
    HandleScope scope;

    Handle<Context> context = Context::GetCurrent();
    Handle<Object> global = context->Global();

    Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
    Handle<Function> JSON_parse = 
Handle<Function>::Cast(JSON->Get(String::New("parse")));

    // return JSON.parse.apply(JSON, jsonString);
    return scope.Close(JSON_parse->Call(JSON, 1, &jsonString)->ToObject());
}

Thanks for looking. =)

-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users

Reply via email to