Re: New to JSON
- From: "Anthony Jones" <Ant@xxxxxxxxxxxxxxxx>
- Date: Thu, 17 Aug 2006 16:02:09 +0100
"Tom Cole" <tcole6@xxxxxxxxx> wrote in message
news:1155823853.756624.48550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks for the tip. What I'm working on (in addition to learning JSON)
is writing an XML to JSON converter. This can be used as a middle tier
to some web services we already have. This way they can still service
existing setups, and provide JSON to newer applications.
This was a snippet of an auto-generated output from this converter. The
XML it came from was:
<headers>
<date>16 Aug 2006 19:53:03 GMT</date>
<header>
<name>accept</name>
<value>*/*</name>
</header>
<header>
<name>accept-language</name>
<value>en-us</value>
</header>
.....
</headers>
So given that, do you have a recommendation that is generic enough to
give a JSON output like what you recommend, but still work with nearly
any XML file?
The problem is that both raw XML and JSON are typeless. A 'generic'
conversion of XML to JSON is simply a non-starter the resulting JSON is
really ugly to use.
Now if you have specific XML schemas that you want to transform to JSON then
you are in with a chance creating an XSL for each.
What benefits do you perceive JSON has over just sticking with XML?
Next I get to figure out how to handle attributes...
Tom Cole wrote:
I'm new to JSON but see how it can be an improvement over XML for some
things.
I've modified a test servlet to return the following string with a
content type of text/x-json:
{ header: { date: "16 Aug 2006 19:53:03 GMT", headers: [ { name:
"accept", value: "*/*" }, { name: "accept-language", value: "en-us" },
{ name: "referer", value: "http://njep11/Ajax/" }, { name:
"content-type", value: "application/x-www-form-urlencoded" }, { name:
"accept-encoding", value: "gzip, deflate" }, { name: "user-agent",
value: "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR
1.0.3705; .NET CLR 1.1.4322)" }, { name: "host", value: "njep11" }, {
name: "content-length", value: "9" }, { name: "connection", value:
"Keep-Alive" }, { name: "cache-control", value: "no-cache" }] } }
On the client side I receive this an create an object via eval:
var object = eval('(' + xmlhttp.respongeText + ')');
If I do an alert(object.toString()) I get [Object object]. So I thought
it was working okay. However if I try to access object.headers[0].name
I get an error stating "headers.0 is null or not an object.
Is my JSON string correct? I'm not sure what role (if any) whitespace
plays in this type. I'm expecting it to create a object of type header
with a variable date and an array of objects that contain name and
value variables.
Thanks in advance.
.
- Follow-Ups:
- Re: New to JSON
- From: Tom Cole
- Re: New to JSON
- References:
- New to JSON
- From: Tom Cole
- Re: New to JSON
- From: Tom Cole
- New to JSON
- Prev by Date: Re: ASP question global.asa
- Next by Date: Re: ASP question global.asa
- Previous by thread: Re: New to JSON
- Next by thread: Re: New to JSON
- Index(es):
Relevant Pages
|