如何将大文本文件转换为json数组格式? [英] how to convert large text file to json array format?

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

问题描述


我想将大文本文件更改为json格式我们能做到吗?我已经尝试将文本文件转换为xls和xls文件到csv和agin csv到json格式但是我面临一些问题,即某些属性更改为null。所以有任何快捷方式将文本文件更改为json文件所有数据。如果有任何请尽快回复。

解决方案

我想你需要



1)用JSON格式解释你的意思和/或检查定义。

2)解释你将使用''代表'文件的JSON数据做什么
$ b例如,你可以这样做:


MyFileStringArray:[文件行1,文件行2] 





但这真的取决于你想用JSON数据做什么 - 你可以将每一行解析/拆分成一些子行/段等,但仍然,这实际上取决于您对数据的需求/想要做什么



'大文本档案'? ..好吧 - 你确实意识到JSON文件会再次变大,不是吗? - 我认为如果你只是想逐行扫描一个文件,转换为JSON不是正确的方法 - 如果你正在索引文件,那么你可能有一个'索引元素'数组,其中每个可能包含一行文件中的数字和索引/关键词



请详细解释您的问题(如果您编辑/更新原始问题则更好)



顺便说一句,您可以将LINQ应用于文本文件以进行扫描/拆分,而无需将它们转换为JSON [/ edit]


< blockquote>提出的问题没有多大意义。 JSON格式只不过是格式;这是'object'类型的JavaScript对象的语法形式。好的,例如,如果你有一些文本,比如说,JavaScript变量, allText ,那么JSON字符串可能看起来像

 {  text:allText; } 



当你打电话给 JSON.stringify https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify [ ^ ])在这个对象上,结果字符串将给出最终结果:它将与上面代码示例中显示的行相同,只有 allText 将是用引号替换它的值。这正是任何其他JSON处理器所做的。



如果你想在一些JSON中解析一些文本文件结构,其中许多属性对应于输入文本的元素,你需要做到这一点。但是你没有对文本结构说一句话,所以用一种通用的方式来表示我所展示的方式。 (正如我所看到的,解决方案1中显示了另一种方式。)它几乎没有任何实际意义......



-SA

Hi I want to change large text file to json format can we do it? I have tried text file to convert to xls and xls file to csv and agin that csv to json format but in that i am facing some proble that is some attribute changes to null .So is there any shortcut to change the text file to json file with all data.If any please kindly response as soon as possible.

解决方案

I think you need to

1) explain what you mean by JSON format and or check the definition.
2) explain what you'll be doing with the JSON data that 'represents' a file

you could, for example, do something like this :-

"MyFileStringArray" : ["File Line 1", "File Line 2"]



but that really depends what you want to DO with the JSON data - you could parse/split each line into some sub-lines/segments etc, but still, that really depends on what you need/want to do with the data

'large text file' ? .. ok - you do realise that the JSON file is going to be larger again, dont you ? - I'd argue if you just want to scan a file line by line, converting to JSON isnt the correct approach - if you're indexing the file, then you may have an array of 'index elements' where each may contain a line number from the file and index/key words

please explain more about your problem (its better if you edit/update your original question)

[edit] btw, you can apply LINQ to text files to scan/split them as well, without the need to convert them to JSON [/edit]


The question, as formulated, makes little sense. JSON format is nothing but just format; this is the form of syntax for a JavaScript object of type 'object'. Okay, if, for example, you have some text in, say, JavaScript variable, allText, the JSON string may look as

{"text": allText; }


When you call JSON.stringify (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify[^]) on this object, the resulting string will give you the final result: it will be the same as the line shown in the code sample above, only allText will be replaced with its value in quotation marks. This is exactly what any other JSON processor will do.

If you want to parse some text file structure in some JSON with many properties corresponding to the elements of the input text, you need to do exactly that. But you did not say a word about the text structure, so one general way to represent the value the way I've demonstrated. (As I can see, another way is shown in Solution 1.) It hardly may make any practical sense…

—SA


这篇关于如何将大文本文件转换为json数组格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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