6

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

1
  • Paste part of your source. What's the error in NB? Maybe it's just a spelling info. Turn off spelling check in NB. Commented Feb 13, 2012 at 15:51

2 Answers 2

15

The code should be

import net.sf.json.JSONObject;
JSONObject JSO = JSONObject.fromObject(practiceInfoByUsername);

Also you need json-lib jar, can be downloaded here.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, It is work, Please Help me get values from That JSON object
JSO.getBoolean(key) == value
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.