Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Parsing a generic data file [Thread Next] Re: Parsing a generic data fileTo: 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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
