简体   繁体   English

JavaScript数据结构

[英]Javascript data structure

I have a script that I'm working on, this script reads a zip file and extracts the contents of the files inside the zip. 我有一个正在使用的脚本,该脚本读取一个zip文件,并提取该zip文件中文件的内容。 What I'm trying to do is send a request to my server in the following format: 我正在尝试以以下格式向服务器发送请求:

file0name,contentfile0;file1name,contentfile1;file2name,contentfile2

Can someone tell me what type of data structure I should use? 有人可以告诉我应该使用哪种类型的数据结构? Is it a list or a JSON object? 是列表还是JSON对象?

https://jsfiddle.net/ker1w6pb/6/ https://jsfiddle.net/ker1w6pb/6/

Assuming you convert your content into a string (which sounds odd to me), you can just POST a JSON data object containing your string: 假设您将内容转换为字符串(这对我来说听起来很奇怪),则只需发布一个包含字符串的JSON数据对象:

 var postData = [{ filename: 'file0', content: 'content0' }, { filename: 'file1', content: 'content1' }, { filename: 'file2', content: 'content2' }]; var postString = postData.reduce(function(previous, current) { return previous + current.filename + ',' + current.content + ';'; }, ''); //post(uri, {data: postString}); document.write(postString); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM