On Fri, Mar 4, 2016 at 12:39 PM Pavel Medvedev <[email protected]> wrote:
> I use built-in JSON.stringify() like this > <https://github.com/pmed/v8pp/blob/master/v8pp/json.hpp#L19>: > > > /// Stringify V8 value to JSON > /// return empty string for empty value > std::string json_str(v8::Isolate* isolate, v8::Handle<v8::Value> value) > { > if (value.IsEmpty()) > { > return std::string(); > } > > v8::HandleScope scope(isolate); > > v8::Local<v8::Object> json = isolate->GetCurrentContext()-> > Global()->Get(v8::String::NewFromUtf8(isolate, "JSON"))->ToObject > (); > v8::Local<v8::Function> stringify = json->Get(v8::String::NewFromUtf8( > isolate, "stringify")).As<v8::Function>(); > > v8::Local<v8::Value> result = stringify->Call(json, 1, &value); > v8::String::Utf8Value const str(result); > > return std::string(*str, str.length()); > } > > > By the way, there is v8::JSON::Parse() function in V8 API, and I'm > wondered why there is no v8::JSON::Stringify() counterpart. > Mainly because there's no C++ stringifier in V8. There's a basic stringifier, but it doesn't support to full glory of proxies, etc.. > > On Wednesday, March 2, 2016 at 11:00:48 AM UTC+3, Yong Wang wrote: >> >> Hi all, >> >> I do not find any api can convert v8::Value to json string. >> Could someone can give me a help? >> >> thanks in advance. >> >> >> -- > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
