简体   繁体   English

在Java中加载和解析CSV

[英]Loading and parsing a csv in java

I would like the community's thoughts on a problem. 我希望社区对此问题有想法。 I created a save and load state in my program. 我在程序中创建了一个保存和加载状态。 When I save, I create a *.csv file which saves out the information in a certain format. 保存时,我创建一个* .csv文件,该文件以某种格式保存信息。 When I load, it loads the parsed *.csv file. 当我加载时,它将加载已解析的* .csv文件。 The issue is when I parse, on my second line it can have as many lines as the user wants because it's a description text box. 问题是当我解析时,在第二行中它可以是用户想要的任意多行,因为这是一个描述文本框。 The format of the csv is like this: csv的格式如下:

User title - 1 line 用户标题-1行

User description - any number of lines 用户描述-任意数量的行

Header -1 line 标头-1行

Address locations -1 line per address 地址位置每个地址-1行

Example: 例:

Myawesometitle, Myawesometitle,

This is a description, 这是一个描述,

A very good description, 很好的描述

Nbr,address, city,state,zip NBR,地址,城市,州,邮政编码

1,5643 marketstreet, Cincinnati, OH, 80985 1,5643 markettreet,辛辛那提,俄亥俄州,80985

2,12345 main avenue, Denver, CO, 67890 美国科罗拉多州丹佛市2,12345主大街67890

How can I get around the user description having multiple lines? 如何绕开多行用户说明? I can parse by either /n or , 我可以用/ n或来解析

Thank you, 谢谢,

If you are not obligated to use CSV specifically I encourage you to use JSON format, it is much more dynamic and schema free, because for example, you can use lists [] as a value, and in you case it suites perfectly to unlimited number of addresses. 如果您没有义务专门使用CSV,则建议您使用JSON格式,因为它可以动态使用且不受架构限制,例如,您可以使用列表[]作为值,并且在这种情况下,它可以完美地适合无限数量地址。

For example: 例如:

{
     "User title" : "Myawesometitle"

     "User description" : "This is a description"

     "Header" : "A very good description"

     "Address locations" :
     [
          {
               "Nbr" : "1,5643"
               "address" : "marketstreet"
               "city" : "Cincinnati"
               "state" : "OH"
               "zip" : "80985"
          }, 
          {
               "Nbr" : "2,12345"
               "address" : "main avenue"
               "city" : "Denver"
               "state" : "CO"
               "zip" : "67890"
          }
    ]
} 

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

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