我正在尝试将以下结构从c ++返回到节点:
{
"hello":"hello there!",
"obj": {
"name":"Karl",
"num":666
}
}
我无法正确地将Local<Object>
纳入另一个Local<Object>
。
以下是代码的主要部分:
Local<Object> obj = Object::New(isolate);
obj->Set(String::NewFromUtf8(isolate, "hello"), String::NewFromUtf8(isolate, "hello there"));
Local<Object> obj_lvl = Object::New(isolate);
obj_lvl->Set(String::NewFromUtf8(isolate, "name"), String::NewFromUtf8(isolate, "Karl"));
obj_lvl->Set(String::NewFromUtf8(isolate, "num"), Integer::New(isolate, 666));
// below here i am trying to include the object "obj_lvl" into the first object "obj"
obj->Set(String::NewFromUtf8(isolate, "obj"), String::NewFromUtf8(isolate, obj_lvl)); // <--- error is here
我收到错误:
../count_node.cc:90:91: error: no matching function for call to ‘v8::String::NewFromUtf8(v8::Isolate*&, v8::Local<v8::Object>&)’
obj->Set(String::NewFromUtf8(isolate, "obj"), String::NewFromUtf8(isolate, obj_lvl));
我一直在寻找一个教程,但它们要么已过时(0.12之前),要么就是不存在。我正在使用节点版本v6.6.0(npm v3.10.3)和node-gyp版本v3.4.0。
同样,Integer::New(isolate, ...));
和Number::New(isolate, ...));
之间存在差异,两者都有。
答案 0 :(得分:0)
因为我已经制作了一个v8对象,所以我必须按原样应用它:
obj->Set(String::NewFromUtf8(isolate, "obj"), obj_lvl);
立即工作。