将csv文件转换为json对象数据表 [英] convert csv file to json object datatable

查看:41
本文介绍了将csv文件转换为json对象数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何获取 csv url 文件并将其转换为 json 对象,以便我可以在 js 中使用 google 图表工具?

Does anyone know how to get a csv url file and convert it to a json object so that I can use google charting tools in js?

推荐答案

据我所知,对于大多数场景,您可以将 csv 转换为 js Array of Arrays、Matrix 或任何跟随您的图表工具的 javascript 对象约定.

As far as I know, for most scenarios, you can turn csv into a js Array of Arrays, a Matrix, or any javascript object that follows your charting tool convention.

您可能需要:

  1. 获取 CSV 文件内容
  2. 解析
  3. 将 2 的结果包装到您的图表工具 json(?) 中
  4. 调用您的图表库

对于 1,如果 CSV 文件托管在您的域中,您可以执行简单的 XMLHttpRequest,否则尝试在此处搜索同源策略".
棘手的部分是第 2 点.我已经看到了几次手动解析 CSV 文件的失败尝试(分号可以作为值的一部分等)......查看链接.

For 1, if the CSV file is hosted in your domain, you can do a simple XMLHttpRequest, else try searching here "same origin policy".
The tricky part is the point 2. I've seen several failed attempts for parsing CSV files by hand (semicolons can be contained as part of the value, etc)... Check out the link.

这篇关于将csv文件转换为json对象数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆