Right now i'm working with SOAP UI and responce i get in ResultSet format. Since i preffer to work more with JSON rather then ResultSet, i found this nice solution that perfectly fits my needs.
Here's the code : Thanks to this blog
Here's the code : Thanks to this blog
Hi,
ReplyDeletewhen I copy the code to eclipse, I get an error for line 44. There seems to be a problem with the quotes.
You're right - the problem was not in code, but in Blogger source code parser - it got broken. I made a Gist snipped, which you can find here - https://gist.github.com/azakordonets/da31d9e74369a9d71b1c . Also, on my personal blog post - http://biercoff.com/nice-and-simple-converter-of-java-resultset-into-jsonarray-or-xml/ formatting is not broken, so for new articles you can look at http://biercoff.com.
ReplyDeleteThanks for noticing
Hi , shouldn't line 26 be out of that inner loop ?
ReplyDeleteYou can see latest updated version here - http://biercoff.com/nice-and-simple-converter-of-java-resultset-into-jsonarray-or-xml/
DeleteThe code is full of errors.
ReplyDeleteBelow is the rectified code for convertToJSON()
public static JSONArray convertToJSON(ResultSet resultSet) throws Exception {
JSONArray jsonArray = new JSONArray();
JSONObject obj;
int total_cols = resultSet.getMetaData().getColumnCount();
while (resultSet.next()) {
obj = new JSONObject();
for (int i = 0; i < total_cols; i++) {
obj.put(resultSet.getMetaData().getColumnLabel(i + 1),
resultSet.getObject(i + 1));
}
jsonArray.put(obj);
}
return jsonArray;
}
Looks like you don't read comments :) As i said, i don't keep this article updated, rather i moved everything to my personal blog.
Delete