JSON string to list with Simple JSON
I'm grabbing a json string from a mysql database with php. What I want to do is to be able to save that json as a CSV file. I know how to make that file with a list, but I'm not sure how to do it with a json string. I know it has to be parsed first, the I would imagine add it to the list, but I'm missing something. public void SaveOilToCSV(string CSVList) { Debug.Log (CSVList);
var oilchangelist = JSON.Parse(CSVList);
foreach(JSONNode oc in oilchangelist)
{
oilchangelist.Add (oc);
}
It spits out an error: InvalidOperationException: Collection was modified; enumeration operation may not execute.
Just for jollys, here is the rest of the code to give you a frame of reference:
List<string>OilChangeList =new List<string>() ;
OilChangeList.Add(CSVList.ToList());
StringBuilder csvcontent = new StringBuilder();
csvcontent.AppendLine("Service Date, Location, Mileage, Labor, Oil Brand, Oil Price, Filter Brand, Filter Price");
for(int i=0; i <OilChangeList.Count; i++ )
{
csvcontent.AppendLine (OilChangeList[i].ServiceDate+", "+OilChangeList[i].Location+", "+OilChangeList[i].Mileage+"," +
" "+OilChangeList[i].Labor+", "+OilChangeList[i].OilBrand+", "+ OilChangeList[i].OilPrice+", "
+OilChangeList[i].FilterBrand+", "+OilChangeList[i].FilterPrice+", "+OilChangeList[i].OilFilterPurchaseLocation);
}
string csvpath= "D:\\xyz.csv";
File.AppendAllText(csvpath, csvcontent.ToString());
Thanks in advance for the help!
Your answer
Follow this Question
Related Questions
SHA512 JS -> C# 0 Answers
JsonUtility and Arrays - JSON must represent an object type. 0 Answers
Refresh Chat room messages 1 Answer
Storing Level Data in Json Text in Streaming Asstes Folder 1 Answer
Json to array of objects C# 1 Answer