Copy link to clipboard
Copied
Hi there,
I am exporting string to csv and have been removeing new lines and commas like so
thing.toString().replace(/\n/g, '').replace(',','') ;
how can I do this iwthout losing the line breaks and commas? I can't have them in atm because messes up the csv.
JSON is for 'transfering' information that can be reassembled into number, string, array, object, etc. format afterwards.
Excel can import CSV but it might not understand the complexity of the information. Tyically what you would do is serialize complex information with JSON, recieve it on the other side (wherever that might be) and then deserialize it. After you deserialize it using JSONs abilities to turn your information back into what is was (numbers, strings, arrays and object) it is up to
...Copy link to clipboard
Copied
If you wanrt to keep them, don't remove them.
Copy link to clipboard
Copied
but they mess up the csv, data in the wrong columns
Copy link to clipboard
Copied
Ditch CSV and try a more robust format like JSON:
We're talking strings, numbers, arrays and objects serialized and deserialized. Just scroll down for a giant list of encoders and decoders in any language of your choice, of course including ActionScript. JSON is used heavily in AJAX JavaScript (which is ECMAScript compliant, just like ActionScript).
Otherwise for superior situations, use the binary AMF protocol.
Copy link to clipboard
Copied
but the users download the csv and open in excel, can it be done in JSON?
Copy link to clipboard
Copied
JSON is for 'transfering' information that can be reassembled into number, string, array, object, etc. format afterwards.
Excel can import CSV but it might not understand the complexity of the information. Tyically what you would do is serialize complex information with JSON, recieve it on the other side (wherever that might be) and then deserialize it. After you deserialize it using JSONs abilities to turn your information back into what is was (numbers, strings, arrays and object) it is up to you how you restructure the data for the format you choose.
Your original intent of preserving CSV is best for Excel or OpenOffice Calc. You didn't mention your intent. JSON would package those (CRLF) \n's for you.