iink SDK Web

Importing the Exported Strokes has different behaviors after JSON stringify()

This is from the code segments of the example file: websocket_math_import_jiix.html.

In the "exported" event handler of the example code websocket_math_import_jiix.html, the exported strokes can be imported and displayed in the second editor successfully:


  editorELement1.addEventListener('exported', (event) => {
    const exports = event.detail.exports;

  if(exports && exports['application/vnd.myscript.jiix']) {
      toImport = exports['application/vnd.myscript.jiix'];
    }
    if(toImport !== null) {
      if(editorELement1.editor.isEmpty) {
        toImport = null;
      } else {
        infosElement.style.visibility = 'hidden';
        editorELement2.editor.import_(toImport, 'application/vnd.myscript.jiix');
      }
    }
  });


So far so good.

However,

if the exported strokes in the JSON format were first stringified and then parsed back to objects, in the second editor the import of the same strokes failed with the message { type: "error", message: "Import error : could not parse imported jiix", code: "import.error" }. Here are the stringified JSON strings and the modified code segments:

"{\n \"type\": \"Math\",\n \"expressions\": [ {\n   \"type\": \"symbol\",\n   \"id\": \"math/12\",\n   \"label\": \"a\",\n   \"items\": [ {\n     \"timestamp\": \"2023-12-29 08:40:14.814000\",\n     \"X\": [ 137.847916, 136.789581, 135.731247, 134.9375, 133.614578, 132.556244, 131.762497, 131.762497,\n      131.762497, 132.556244, 134.143753, 134.9375, 135.46666, 135.731247, 136.524994, 137.054169,\n      137.583328, 137.847916, 137.847916, 137.847916, 138.377075, 138.90625, 138.90625, 139.170822 ],\n     \"Y\": [ 24.8708324, 25.135416, 24.8708324, 24.8708324, 25.135416, 26.1937485, 29.6333332, 30.6916656,\n      31.75, 32.0145836, 32.0145836, 32.0145836, 31.2208328, 30.4270821, 28.3104153, 26.7229156,\n      25.9291668, 24.8708324, 25.6645832, 27.2520828, 28.0458317, 29.3687496, 30.1624985, 32.0145836 ],\n     \"F\": [ 0.5, 0.796945691, 0.718526483, 0.6761536, 0.746184707, 0.759273291, 0.634737551, 0.714515865,\n      0.714515865, 0.683189929, 0.766522586, 0.6761536, 0.700710416, 0.683189929, 0.806067288, 0.772879839,\n      0.700710416, 0.718526483, 0.6761536, 0.766522586, 0.700710416, 0.753112853, 0.6761536, 0.78587532 ],\n     \"T\": [ 0, 270, 403, 470, 598, 703, 804, 870,\n      937, 1036, 1198, 1236, 1270, 1304, 1403, 1471,\n      1537, 1670, 2040, 2070, 2235, 2270, 2303, 2411 ],\n     \"type\": \"stroke\",\n     \"id\": \"0000000001002f00ff00\"\n    } ]\n  } ],\n \"id\": \"MainBlock\",\n \"version\": \"3\"\n}"


  editorELement1.addEventListener('exported', (event) => {
    const exports = event.detail.exports;

  if(exports && exports['application/vnd.myscript.jiix']) {
      toImport = JSON.parse(JSON.stringify(exports['application/vnd.myscript.jiix']));
    }
    if(toImport !== null) {
      if(editorELement1.editor.isEmpty) {
        toImport = null;
      } else {
        infosElement.style.visibility = 'hidden';
        editorELement2.editor.import_(toImport, 'application/vnd.myscript.jiix');
      }
    }
  });

Here are the error trails:

Error while firing the recognition
Object { type: "error", message: "Import error : could not parse imported jiix", code: "import.error" }
RecognizerService.js:121:11
    handleError RecognizerService.js:121
    responseCallback iinkWsRecognizer.js:270
    patch iinkWsRecognizer.js:360
    buildWebSocketCallback WsBuilder.js:131
    onmessage networkWSInterface.js:77
    (Async: EventHandlerNonNull)
    openWebSocket networkWSInterface.js:68
    init$1 WsRecognizerUtil.js:47
    _callee2$ iinkWsRecognizer.js:313
    Babel 8
    initialize Editor.js:541
    set Editor.js:575
    set Editor.js:497
    set Editor.js:394
    Editor Editor.js:361
    register EditorFacade.js:16
    <anonymous> websocket_math_import_jiix_copy.html:121
    <anonymous> websocket_math_import_jiix_copy.html:103

Can you tell me what is wrong with the importing strokes after the stringify() and parse() sequences of the JSON strokes objects?

1 Comment

Hello,


Thank you for your question.

Could you please share you entire html file including the code where your instantiate your objects, please?


Best regards,


Gwenaëlle

Login or Signup to post a comment