stleary / JSON-java

A reference implementation of a JSON package in Java.
http://stleary.github.io/JSON-java/index.html
Other
4.54k stars 2.56k forks source link

JSONML failing on comments #56

Closed danieltan closed 12 years ago

danieltan commented 12 years ago

When using JSONML to convert XML into JSON, there seems to be an issue when encountering comments.

I think the issue is at line 95:

                    c = x.next();
                    if (c == '-') {
                        if (x.next() == '-') {
                            x.skipPast("-->");
                        }
                        x.back();
                    } else if (c == '[') {

Should there be an else before the x.back(), or maybe the x.back() shouldnt even be in there.

douglascrockford commented 12 years ago

Do you have a test case?

danieltan commented 12 years ago

Hi Douglas,

Thanks for the quick reply. My simple test case is an XML like below:

In my code, I have an XMLBeans object called thm which I convert to a JSONML object in order to write in my jsp response:

JSONObject json = JSONML.toJSONObject(thm.toString()); String jsonString = json.toString(); req.response.setContentType("application/json"); writer.write(jsonString);

The response I get back is: {"id":"test","xmlns:them":"http://www.idelve.net/xmlbeans/themes","tagName":"xml-fragment","childNodes":[{"tagName":"them:layer-draw-order","childNodes":[">"]}]}

You can note that there is an extra ">" in there from the comment.

Thanks,

Dan

-----Original Message----- From: Douglas Crockford [mailto:reply@reply.github.com] Sent: Monday, 28 May 2012 9:08 PM To: Daniel Tan Subject: Re: [JSON-java] JSONML failing on comments (#56)

Do you have a test case?


Reply to this email directly or view it on GitHub: https://github.com/douglascrockford/JSON-java/issues/56#issuecomment-5965065

douglascrockford commented 12 years ago

Thanks. Please try it now.

danieltan commented 12 years ago

That looks great!

Thanks,

Dan

-----Original Message----- From: Douglas Crockford [mailto:reply@reply.github.com] Sent: Wednesday, 30 May 2012 4:43 AM To: Daniel Tan Subject: Re: [JSON-java] JSONML failing on comments (#56)

Thanks. Please try it now.


Reply to this email directly or view it on GitHub: https://github.com/douglascrockford/JSON-java/issues/56#issuecomment-5995206