Greetings all,
-- All of the below FYI
Some time ago I wrote http://www.netkernel.org/forum/topic/534/1. I haven''t been able to check the JSON implementation in NK4, but there''s some other funy stuff in the NK3 implementation ...
Say you want to return this :
That may not look like a lot, but a lot of services require your result to be like that. So you start writing your service and you end up with the following XML :
<root>
<errors></errors>
<success>true</success>
</root>
Nice, but how to convert this valid XML that to the above (valid) JSON. The answer is ... you can''t. The conversion will keep the root element (which has to be there in order to have valid XML ... and that closes the circle).
In order to resolve this I hacked the JSONAspect.java source as follows :
Simply put, if the root-tag is <removeme>, it gets ... you guessed it ... removed (only the tag, not the content).
There''s another issue with the NK3 implementation of JSONFromXML that does something wrong. For one reason or another the resulting JSON will always look like :
{
"errors": {},
"success": "true"
}
Note the double quotes around the boolean value. Same happens with numbers. Probably I do not understand the correct syntax in this case, I do see relevant code in the JSONObject.java source (valueToString method to be exact), it just doesn''t work for me. Wrote an ugly hack for the boolean values (since yes, the services I work with require a boolean to be without the quotes).
Enjoy,
Tom
-- All of the below FYI
Some time ago I wrote http://www.netkernel.org/forum/topic/534/1. I haven''t been able to check the JSON implementation in NK4, but there''s some other funy stuff in the NK3 implementation ...
Say you want to return this :
{ |
That may not look like a lot, but a lot of services require your result to be like that. So you start writing your service and you end up with the following XML :
<root>
<errors></errors>
<success>true</success>
</root>
Nice, but how to convert this valid XML that to the above (valid) JSON. The answer is ... you can''t. The conversion will keep the root element (which has to be there in order to have valid XML ... and that closes the circle).
In order to resolve this I hacked the JSONAspect.java source as follows :
/* |
Simply put, if the root-tag is <removeme>, it gets ... you guessed it ... removed (only the tag, not the content).
There''s another issue with the NK3 implementation of JSONFromXML that does something wrong. For one reason or another the resulting JSON will always look like :
{
"errors": {},
"success": "true"
}
Note the double quotes around the boolean value. Same happens with numbers. Probably I do not understand the correct syntax in this case, I do see relevant code in the JSONObject.java source (valueToString method to be exact), it just doesn''t work for me. Wrote an ugly hack for the boolean values (since yes, the services I work with require a boolean to be without the quotes).
Enjoy,
Tom