dc.js send dimension data to node.js server in json format, then using java to process the data dc.js send dimension data to node.js server in json format, then using java to process the data json json

dc.js send dimension data to node.js server in json format, then using java to process the data


You can use org.json.JSONObject library for converting string into json object and then retrieve the elements.

String json1 = "{\"Account\":\"789\",\"Date\":\"2013-07-31\",\"Unique Id\":\"2013073101\",\"Tran Type\":\"TFR OUT\",\"Cheque Number\":\"\",\"TranCode\":\"MB TRANSFER\",\"ThirdPartyAccount\":\"123\",\"Amount\":\"-20\",\"formatedDate\":\"2013-07-30T12:00:00.000Z\"}";    JSONObject jsonObject = new JSONObject(json1);    if (jsonObject.has("ThirdPartyAccount")) {        String thirdPartyAccount = jsonObject.getString("ThirdPartyAccount");        System.out.println(thirdPartyAccount);    }

Try it.


{"Account":"789","Date":"2013-07-31","Unique Id":"2013073101","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-30T12:00:00.000Z"}{"Account":"789","Date":"2013-07-30","Unique Id":"2013073005","Tran Type":"TFR IN","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}{"Account":"789","Date":"2013-07-30","Unique Id":"2013073004","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-29T12:00:00.000Z"}{"Account":"789","Date":"2013-07-30","Unique Id":"2013073003","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}{"Account":"789","Date":"2013-07-30","Unique Id":"2013073002","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-160","formatedDate":"2013-07-29T12:00:00.000Z"}{"Account":"789","Date":"2013-07-30","Unique Id":"2013073001","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"160","formatedDate":"2013-07-29T12:00:00.000Z"}

If you assured about order of your dimension not changed and to large amount dimension, Then you can go for below json (Note: null not acceptable)

{  "Account": [    789,    789,    789  ],  "Date": [    "2013-07-31",    "2013-07-30",    "2013-07-31"  ],  "Unique Id": [    2013073101,    2013073102,    2013073103  ]}

And you can parse it easily from java client side, Each index applicable for all JSONArray, I choose few keys and values for showing my JSON structure.


Try gson, you can parse from string to json very simple

private static JsonParser jp = new JsonParser();String data = "......." // your data string hereJsonObject = jp.parse(data).getAsJsonObject();