2016-10-07 64 views
0

我試圖返回下面的結構從C++到節點:對象在從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

你在問什麼?作爲第二個參數,'NewFromUtf'沒有超過'Local '的問題,那有什麼問題?請澄清。 – Rakete1111

+0

@ Rakete1111更新!我試圖將第一個對象中的字段「設置」爲我創建的第二個對象。 –

回答

0

因爲我已經做了V8對象我不得不運用它,因爲它是:

obj->Set(String::NewFromUtf8(isolate, "obj"), obj_lvl); 

工作現在。