Showing posts with label nodejs. Show all posts
Showing posts with label nodejs. Show all posts

Wednesday, March 19, 2014

NodeJS: How to return a JSON parsed object from v8

  string s = jvalue.toStyledString();
  v8::Handle<v8::Value> vs = cvv8::CastToJS(s);

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

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

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