How to extract required information from a file in Java? -


here contents of file:

  {"s_raw_message2":"something","connection_method":"wms","i_rxbufferlength":"2638","o":"1","device_offset":"system=0#0;application=0#0;security=20150703100915.620080-000#984726;","s_reporterhost":"ip","connection_mode":"wmsapp","s_rv25":"ff98ca90-0394-1033-b130-001d92dd737d","i_trustdevicetime":"","s_rv24":"3642bcf0-0394-1033-8342-7c050726582f","s_rv23":"3642bcf0-0394-1033-8310-7c050726582f","s_reporterport":"49289","s_rv22":"6d6f80b1-02df-1033-851d-001d92dd737d","s_version":"2011.1r4-201409300209-release","s_rv21":"c76d2820-c395-1029-bb86-001321b5c0b3","s_rxbufferstring":"something","s_observerhost":"ip","s_chainsequence":"34","s_sha256hash":"dee6e845e41c65d5839198c7dd1052c5de7a53fcd885d3eb1d5491d2322c1a96","s_chainid":"1435917933352","s_observerip":"ip"}   {"s_raw_message2":"something","connection_method":"wms","i_rxbufferlength":"2638","o":"1","device_offset":"system=0#0;application=0#0;security=20150703100915.620080-000#984726;","s_reporterhost":"ip","connection_mode":"wmsapp","s_rv25":"ff98ca90-0394-1033-b130-001d92dd737d","i_trustdevicetime":"","s_rv24":"3642bcf0-0394-1033-8342-7c050726582f","s_rv23":"3642bcf0-0394-1033-8310-7c050726582f","s_reporterport":"49289","s_rv22":"6d6f80b1-02df-1033-851d-001d92dd737d","s_version":"2011.1r4-201409300209-release","s_rv21":"c76d2820-c395-1029-bb86-001321b5c0b3","s_rxbufferstring":"something","s_observerhost":"ip","s_chainsequence":"34","s_sha256hash":"dee6e845e41c65d5839198c7dd1052c5de7a53fcd885d3eb1d5491d2322c1a96","s_chainid":"1435917933352","s_observerip":"ip"} 

there similar entries in file want extract information file , store in file in form of key value pairs e.g:

s_raw_message2 connection_method wms  //and on 

please me write java program this.

your code looks json file,

{   "u1":{ "uname":"priya","age":22,"country":"india"},  "u2":{ "uname":"usha","age":22,"country":"india"},  "u3":{ "uname":"dharshini","age":22,"country":"india"},  "u4":{ "uname":"mom","age":22,"country":"india"},  "u5":{ "uname":"dad","age":22,"country":"india"},  "u6":{ "uname":"sis","age":22,"country":"india"},  "u7":{ "uname":"bro","age":22,"country":"india"}  } 

you can parse json file using ajax request code,

<script type="text/javascript">  function ajax_get_json()      {      var hr = new xmlhttprequest();      hr.open("get", "json/mylist.json", true);      hr.setrequestheader("content-type", "application/json",true);      hr.onreadystatechange = function() {          if(hr.readystate == 4 && hr.status == 200) {             /*  var return_data = hr.responsetext; */             var data=json.parse(hr.responsetext);             var status=document.getelementbyid("status");             status.innerhtml = "";             /* status.innerhtml=data.u1.country;  */             for(var obj in data)                 {                 status.innerhtml+=data[obj].uname+" in "+data[obj].country+"<br/>";                }          }     }     hr.send(null);      status.innerhtml = "requesting..."; } </script> <body> <div id="status"></div> <script type="text/javascript">ajax_get_json();</script> </body> </html> 

Comments