You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2020/08/13 01:22:16 UTC

[GitHub] [incubator-echarts] peach5460 opened a new issue #13114: 内部的id生成机制似乎有问题

peach5460 opened a new issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114


   ### Version
   4.8.0
   
   ### Steps to reproduce
   第一步,我new了一个option,里面有一个graphic指定为
   ```
   {
       type: 'line',
       shape: {
       x1: myChart.convertToPixel({ xAxisIndex: 0 }, 8),
       y1: myChart.convertToPixel({ yAxisIndex: 0 }, 0),
       x2: myChart.convertToPixel({ xAxisIndex: 0 }, 8),
       y2: myChart.convertToPixel({ yAxisIndex: 0 }, 0) - axisticklegth,
     },
       style: {
       stroke: 'black'
     }
   }
   ```
   然后,我获取op转为字符串传给后端...
   ```
   function getChart() {
       var op = myChart.getOption();
       return JSON.stringify(op);
   }
   ```
   发现,获取到的op内属性是正常的,但是通过JSON.stringify以后的json字符串不正常,多了很多转义字符
   ![企业微信截图_20200813092125](https://user-images.githubusercontent.com/3350332/90083927-6fb7ff00-dd46-11ea-92d1-0591dfdddbf2.png)
   
   ### What is expected?
   希望能不要转json的时候出来这些转义字符
   
   ### What is actually happening?
   这些转义字符会导致后端处理完json后回传的时候    var op = JSON.parse(option);解析错误...
   echarts的id生成函数是否存在编码字符集问题???
   
   <!-- This issue is generated by echarts-issue-helper. DO NOT REMOVE -->
   <!-- This issue is in English. DO NOT REMOVE -->


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart edited a comment on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
plainheart edited a comment on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-673260151


   源码中关于自动生成 `id` 和 `name` 使用的是 `\0` 而非空格,这是导致 `JSON.stringify` 序列化后出现 `\u0000` 的原因。
   建议为每个元素指定一个ID,避免使用ECharts自动生成的ID。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart edited a comment on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
plainheart edited a comment on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-673260151


   源码中关于自动生成 `id` 和 `name` 使用的是 `\0` 而非空格,这是导致 `JSON.stringify` 序列化后出现 `\u0000` 的原因。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart commented on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
plainheart commented on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-673260151


   源码中关于自动生成 `id` 和 `name` 使用的是 `\0` 而非空格,这是导致 `JSON.stringfiy` 序列化后出现 `\u0000` 的原因。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart commented on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
plainheart commented on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-675802271


   恐怕还是转义问题,使用 `JSON.stringify` 序列化之后的字符串中包含的 `\u0000` 空字符如 [这里](https://stackoverflow.com/questions/48668314/javascript-json-parse-with-u0000) 所说,应当被转义一次。
   ```js
   JSON.parse('{"id": "\\u0000"}'); // OK
   
   JSON.parse('{ "id": "\u0000" }'); // ERROR
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] peach5460 commented on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
peach5460 commented on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-675791188


   > 后端传回是什么?这是否是后端对 json 的处理有些问题?
   
   最初的这个shape-line是前端js自动生成的,生成的时候我只设置了线段的两个端点的坐标值,id由echart自动生成。
   后来我后端获取了这个line的值,对两个端点进行了修改后回传,发现前端就报错了。
   一开始我以为是后端获取的时候字符集转换有问题。
   但是后来我在前端打印json后发现,前端对echart的option属性进行JSON.stringify后就已经有了这些uncode值了。
   
   我知道\u0000是一个合法的json字符,但是显然JSON.stringify没有对其提供支持。
   我搜了一些资料,有人说不支持是有理由的。我也不知道这个说法对不对。而且我似乎也没找到js上有别的json序列化库可用。
   我是一个后端人员,对前端的这些梗不是太熟悉,但是显然,echarts和JSON.stringify之间有一个匹配问题。
   我不知道这两个第三方库到底孰对孰错,但是我希望在官方层面来解决这个问题,而不是我手动给我new出来的每一个shape都赋值一个guid。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart edited a comment on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
plainheart edited a comment on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-675802271


   恐怕还是转义问题,使用 `JSON.stringify` 序列化之后的字符串中包含的 `\u0000` 空字符如 [这里](https://stackoverflow.com/questions/48668314/javascript-json-parse-with-u0000) 所说,应当被转义一次。
   ```js
   JSON.parse('{"id": "\\u0000"}'); // OK
   
   JSON.parse('{"id": "\u0000"}'); // ERROR
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] echarts-bot[bot] commented on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
echarts-bot[bot] commented on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-673192541


   Hi! We've received your issue and please be patient to get responded. 🎉
   The average response time is expected to be within one day for weekdays.
   
   In the meanwhile, please make sure that **you have posted enough image to demo your request**. You may also check out the [API](http://echarts.apache.org/api.html) and [chart option](http://echarts.apache.org/option.html) to get the answer.
   
   If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org. Please attach the issue link if it's a technical questions.
   
   If you are interested in the project, you may also subscribe our [mail list](https://echarts.apache.org/en/maillist.html).
   
   Have a nice day! 🍵


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] peach5460 commented on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
peach5460 commented on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-675215166


   额……使用\0是有什么历史渊源吗?
   虽然我每个元素都自己手动指定一下ID并不困难,但是我还是很想知道,这么设计的初衷是什么


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] 100pah commented on issue #13114: 内部的id生成机制似乎有问题

Posted by GitBox <gi...@apache.org>.
100pah commented on issue #13114:
URL: https://github.com/apache/incubator-echarts/issues/13114#issuecomment-675330090


    \u0000 是个合法的 json 字符,
   `'\0' === '\u0000'`
   
   > 这些转义字符会导致后端处理完json后回传的时候 var op = JSON.parse(option);解析错误...
   
   后端传回是什么?这是否是后端对 json 的处理有些问题?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org