I want to create JSON object from JSON data receive from server as A String.
I receive following JSON data from server to String "practiceInfoByUsername"
{
"method_name": "getMyPracticeInfo",
"module_name": "pciLoc",
"result_set": [
{
"practice_address": {
"state_province": "GA",
"_types": [
"Address"
],
"county_district": "",
"address1": "1111 Test Street",
"address2": "",
"city_village": "Atlanta",
"longitude": "",
"subregion": "",
"postal_code": "00000",
"township_division": "",
"country": "USA",
"latitude": "",
"region": "",
"_cls": "Address"
},
"ucf_fee_group_id": 0,
"practice_type": "H",
"practice_website": "",
"insurance_plan_fee_group_id": 0,
"practice_edi_vendor_id": "",
"practice_comments": "",
"practice_date_changed": "2011-10-14 17:48:14",
"practice_entity_id": "E01",
"practice_pref_use_metric": true,
"practice_changed_by": "",
"practice_message_on_patient_statement": "",
"practice_fax": "",
"practice_def_birth_year": 1930,
"practice_id": "P01",
"practice_ein": "",
"practice_npi": "",
"practice_phone": "",
"practice_email": "",
"practice_name": "Test Practice #1",
"practice_depts": [
{
"d_name": "Accident and emergency",
"d_type": "AE",
"d_code": "EMER",
"d_notes": ""
},
{
"d_name": "Cardiology",
"d_type": "CA",
"d_code": "CARD",
"d_notes": ""
},
{
"d_name": "Diagnostic imaging",
"d_type": "DI",
"d_code": "DIAG",
"d_notes": ""
},
{
"d_name": "Obstetrics and gynaecology",
"d_type": "OB",
"d_code": "OBG",
"d_notes": ""
}
]
}
],
"rec_count": 1
}
I have Use following Code for create JSON object
JSONObject JSO = new JSONObject(practiceInfoByUsername);
But it is mark as wrong in Netbeans my String name "practiceInfoByUsername" underline in red colour
I think I have mistake in configuring JSON library for Netbeans
please help me
The code should be
import net.sf.json.JSONObject;
JSONObject JSO = JSONObject.fromObject(practiceInfoByUsername);
Also you need json-lib jar, can be downloaded here.
I would recommend you to use a library for json .. there are plenty of them. The most used (from what I know), is google-gson .. good documentation and examples along the web also ..
You can also take a look here .. for an overview of the JSON-tools.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With