Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

json.md 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ## JSON
  2. The _JSON_ object provides the c++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object.
  3. - <a href="#api_nan_json_parse"><b><code>Nan::JSON.Parse</code></b></a>
  4. - <a href="#api_nan_json_stringify"><b><code>Nan::JSON.Stringify</code></b></a>
  5. Refer to the V8 JSON object in the [V8 documentation](https://v8docs.nodesource.com/node-8.11/da/d6f/classv8_1_1_j_s_o_n.html) for more information about these methods and their arguments.
  6. <a name="api_nan_json_parse"></a>
  7. ### Nan::JSON.Parse
  8. A simple wrapper around [`v8::JSON::Parse`](https://v8docs.nodesource.com/node-8.11/da/d6f/classv8_1_1_j_s_o_n.html#a936310d2540fb630ed37d3ee3ffe4504).
  9. Definition:
  10. ```c++
  11. Nan::MaybeLocal<v8::Value> Nan::JSON::Parse(v8::Local<v8::String> json_string);
  12. ```
  13. Use `JSON.Parse(json_string)` to parse a string into a `v8::Value`.
  14. Example:
  15. ```c++
  16. v8::Local<v8::String> json_string = Nan::New("{ \"JSON\": \"object\" }").ToLocalChecked();
  17. Nan::JSON NanJSON;
  18. Nan::MaybeLocal<v8::Value> result = NanJSON.Parse(json_string);
  19. if (!result.IsEmpty()) {
  20. v8::Local<v8::Value> val = result.ToLocalChecked();
  21. }
  22. ```
  23. <a name="api_nan_json_stringify"></a>
  24. ### Nan::JSON.Stringify
  25. A simple wrapper around [`v8::JSON::Stringify`](https://v8docs.nodesource.com/node-8.11/da/d6f/classv8_1_1_j_s_o_n.html#a44b255c3531489ce43f6110209138860).
  26. Definition:
  27. ```c++
  28. Nan::MaybeLocal<v8::String> Nan::JSON::Stringify(v8::Local<v8::Object> json_object, v8::Local<v8::String> gap = v8::Local<v8::String>());
  29. ```
  30. Use `JSON.Stringify(value)` to stringify a `v8::Object`.
  31. Example:
  32. ```c++
  33. // using `v8::Local<v8::Value> val` from the `JSON::Parse` example
  34. v8::Local<v8::Object> obj = Nan::To<v8::Object>(val).ToLocalChecked();
  35. Nan::JSON NanJSON;
  36. Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(obj);
  37. if (!result.IsEmpty()) {
  38. v8::Local<v8::String> stringified = result.ToLocalChecked();
  39. }
  40. ```