4 Replies - 11812 Views - Last Post: 17 October 2012 - 06:36 AM Rate Topic: -----

#1 Lazyhermit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-October 12

JSON-Excel Parser. What is the next move?

Posted 15 October 2012 - 01:39 PM

Hello everyone,

I have been assigned the task of writing up a JSON to Excel Parser in C# and after subconsciously thinking about it throughout the weekend and coming up with nothing, I thought it best to ask my fellow anonymous.

Right now the program is, what i would assume, halfway through. I am able to extract the JSON string located in a file and sort out all of its contents. into a giant List/Tree of my own design.(See Below)
public struct Treenode
        {
            public string Title;
            public object Data;
            public List<Treenode> child;

            public Treenode(string Title) { this.Title = Title; this.Data = null; this.child = null; }
            public Treenode(string Title, object Data) { this.Title = Title; this.Data = Data; this.child = null; }
            public Treenode(string Title, object Data, Treenode child)
            {
                this.Title = Title;
                this.Data = Data;
                this.child = new List<Treenode>();
                this.child.Add(child);
            }

        }



I've read many ill remarks involving Structs in C#, but I am really just learning it as I go. So bear with me if my code is a finely woven mesh of mush.

So I have all the data from the JSON string in a scalable List. And I'm stumped. I can't fathom how to keep all this information sorted correctly once I start putting it in an Excel file.

So I ask you now, my fellow coders: what do you think I should do?

Is This A Good Question/Topic? 0
  • +

Replies To: JSON-Excel Parser. What is the next move?

#2 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: JSON-Excel Parser. What is the next move?

Posted 16 October 2012 - 07:30 AM

Well, first I'd start here:

http://json.codeplex.com/

JSON.net is a pre-existing json parser, so you can at least skip that step. That should work as a fully fleshed out JSON tree parser so you can work on your excel logic, which I just can't help you with, because I don't know how you'd want to represent that data in excel.

Also, people are down on structs because for the most part, classes do what you want, and can do more besides. You could change your struct to a class without changing anything else.
Was This Post Helpful? 0
  • +
  • -

#3 Lazyhermit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-October 12

Re: JSON-Excel Parser. What is the next move?

Posted 16 October 2012 - 02:57 PM

I should have stated that I am already using Newtonsoft.Json.JsonTextReader to read in the Json string and evaluate the content in my tree.

I understand that JSON.Net has a simple call to serialize/deserialize Json strings and put it into XML. But I'd really prefer not having to go through XML to get to Excel.

And evidently empty arrays are removed from the Json string on JsonConvert.DeserializeXmlNode. Which is nice but I don't want to lose any information.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: JSON-Excel Parser. What is the next move?

Posted 16 October 2012 - 03:00 PM

Well, then I don't know what to tell you. I don't know how you want this data represented in a spreadsheet, because JSON data can be formatted in an infinite amount of ways, and has no schema. Is there a particular data structure you have in mind to represent, or is this any arbitrary json?
Was This Post Helpful? 0
  • +
  • -

#5 Lazyhermit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-October 12

Re: JSON-Excel Parser. What is the next move?

Posted 17 October 2012 - 06:36 AM

I'm trying to see what others do in this situation when transferring data from a data structure of unknown depth and breadth to an Excel doc in such a way that in the future I can use a reverse parser to go from Excel to Json without ommitting empty values/arrays.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1