Reputation: 135
Hello I have a problem to parse any JSON
in IIB
Toolkit. The exception thrown by java compute node is: java.lang.NoClassDefFoundError: org.json.JSONObject
I am parsing incoming JSON
messages in UTF-8
. I already tried to get them in JSON
, but accepting them as BLOB
and converting to JSON UTF-8
works for me.
String messageText = new String(outMessage.getRootElement().getLastChild().getLastChild().getValueAsString());
messageText = new String(DatatypeConverter.parseHexBinary(messageText),"UTF-8");
JSONObject json = new JSONObject("{}");
I would love to create JSON
object from JSON
string in UTF-8
Many thanks in advance!
Upvotes: 1
Views: 2239
Reputation: 3041
So what you are trying to do is a bit of a no-no. You're trying to use the Java class JSONObject rather than using the builtin IIB Java Parser.
Have a look at MbElement in particular the methods createElementAsLastChild(java.lang.String parserName) and createElementAsLastChildFromBitstream.
As per my earlier answer never forget your are trying to build a tree of elements.
One other trick I sometimes use is to build a sample output message and send it to an Input node connected to a Trace node. I then use the Trace node output to write code to build my actual output tree, you can even put a Trace node after your JavaCompute node to see what the Element tree you've currently built looks like and correct your mistakes. I mostly use this method for SOAP messages which can be quite complex.
If you really want to use external Java classes then search for Using JAXB with a JavaCompute node and follow the links from that article.
Upvotes: 2