Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Parsing a generic data file

From: "Anthony Jones" <Ant@------------.--->
To: NULL
Date: 12/14/2007 8:13:00 PM

"Jasper" <notaround@d...> wrote in message
news:OrOdnauTgOGTyv_anZ2dnUVZ8q2dnZ2d@p......
>
> "msnews.microsoft.com" <joefawcett@n...> wrote in message
> news:uCJiYxiPIHA.3556@T......
> > "Jasper" <notaround@d...> wrote in message
> > news:2p-dnWHym_54YPzaRVnyvAA@p......
> >> Hi, Maybe this is off-topic, but perhaps you can help. I'm looking for
> >> ideas on how to parse a data file.
> >>
> > Looks like JSON to me, search for a JSON library.
> > JSON is a way of representing objects using string literals that is used
> > for passing information to clients that use JavaScript.
> >
>
> Does it? Makes sense if that's true. I was sure it fit some sort of "web
> format" but I didn't know which.
> I presume there must be some sort of C++ code available to parse it out.
>

It is JSON.  You would need to be looking at the Javascript  eval method to
parse it.  The returned object would then have a heiarchy you could pull
data from e.g.:-

var x = o.Class.Subject

x == "Politics" // will be true

However the structure is somewhat suspect.

The students array contains only one object on which all students are
placed.  Each student having their last name as the attribute ID for their
object (what happens if the class is attended by more than one Smith?).
This object is in turn an array containing only one object.

The Grades array suffers the same problem where again inappropriate use of
{ } causes the array to contain only one object and in this case the same
identifier "Test" used multiple times resulting in it being redefined and
only containing the last entry.

Here is a cleaner version (although I'm not entirely happy with the
identifiers "Last Name" and "First Name" containing a space it is legal):-

{

"teacher":{
  "name": "Mr Borat",
  "age": 35,
  "Nationality": "Kazakhstan"
},


"Class":{
  "Semester": "Summer",
  "Room": null,
  "Subject": "Politics",
  "Notes": "We're happy, you happy?"
},

"Students":
[
  {"Last Name":"Smith",
    "First Name":"Mary","sex":"Female"},
  {"Last Name":"Brown",
    "First Name":"John","sex":"Male"},
  {"Last Name":"Jackson",
    "First Name":"Jackie","sex":"Female"}
],


"Grades":
[
    {"Test":"Name of a Test",
        Points: {"A":68,"B":25,"C":15}}
    {"Test":"Name of a different test",
        Points: {"A":55,"B":29,"C":2}}
    {"Test": "Name of yet another test",
        Points:  {"A":72,"B":65,"C":2}}
]

}


-- 
Anthony Jones - MVP ASP/ASP.NET




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent