Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I took response from server using bluetooth got like this. then i need to get take data from String.

String is like
JavaScript
String result="
 {
    "odata.metadata":"//localhost:33396/FalconCPDataService.svc/$metadata#DEPatients",
    "value":[
    {
    "PatientID":"91b151ed-89df-4145-b131-2b545b1d95dd",
    "FirstName":"nbTaz+YZdJV6fIKDjOAjXA==",
    "LastName":"CFTX/btPoNFBqPgPOkabaA==",
    "DOB":"Bwu/UDNARSVBRQdjGAwL2b4tUjZU97LzGj3ca8Pvzd9ppnyh/dTUXvddx9Eq/ojdFx4sF2pRe0nl7+9JTqLyWw==",
    "CreationDate":"2012-10-30T03:12:53.827",
    "LastModifiedDate":"2012-09-25T12:44:50",
    "MiddleName":"",
    "Gender":"S06R4AMwd41fvMeYPLsZxg==",
    "Height":null,
    "Weight":null,
    "SSN":null,
    "ClinicID":null,
    "PatientClinicID":"",
    "Address1":"",
    "Address2":"",
    "City":"",
    "State":"",
    "ZipCode":"",
    "Country":"",
    "PrimaryPhone":"",
    "SecondaryPhone":"",
    "Notes":"",
    "Inactive":false,
    "CRC":47329
    },
    {
    "PatientID":"2cc150b4-06c0-4b98-a63e-32dacbdb258f",
    "FirstName":"dNgKH5cYdpf+NvxZsw+gRg==",
    "LastName":"kmUqarols8Gb6me2kUOaDWoQ25nzJ3YffC8sjdfYj0w=",
    "DOB":"CnvJ4Xs8FB1eXD4au+ZTRUDZ8ZQqkmIKZuEZKi7vSDD+4hE2Jl59w+fJdy/L0sQrcEDuzv5Ez/8Df1s3P/kOUA==",
    "CreationDate":"2012-10-31T12:21:45.563",
    "LastModifiedDa12T14":"54:38",
    "MiddleName":"",
    "Gender":"S06R4AMwd41fvMeYPLsZxg==",
    "Height":null,
    "Weight":null,
    "SSN":null,
    "ClinicID":null,
    "PatientClinicID":"dg3nfMCL5/wrFUdhB+MorMN+isAaFsnk5W9EBFNkN18=",
    "Address1":"5fM+rMAOBRUQRWmOFkbZrvqxDz8Bsmnht7bHQRRyGI98xNYLt1eStX52GteM8cOM",
    "Address2":"Zl0i8Q52dfck5FqG7d15Fv2nB6XEm2baZ9HspAP1Ka0=",
    "City":"ky7YUme4tegHlbsmQDXeYII5SRpPpcEJi7SH8ElFAqA=",
    "State":"lm5w6lt940OdZgGlRUBqhdE1YkRPCNXpJr4/gJdHByw=",
    "ZipCode":"oOHe4pRq7CNyTAGTNm/PAA==",
    "Country":"9PqNNtxyf6FjuhrPAzJZ6w==",
    "PrimaryPhone":"u50vlWEXjt6SgKBE/T1Af7S5VyTeZPtiFIASgSVUhEU=",
    "SecondaryPhone":"u50vlWEXjt6SgKBE/T1Af4sZyXBNql3RshM3gmgafWg=",
    "Notes":"",
    "Inactive":false,
    "CRC":3869
    }
    ]
    }

I tried like this

JavaScript
JSONObject nodeRoot;
                        try {
                            nodeRoot = new JSONObject(readMessage);
                             // Creating a sub-JSONObject from another JSONObject
                             JSONObject nodeStats = nodeRoot.getJSONObject("value");

                             // Getting the value of a attribute in a JSONObjectzz
                             String sSDR = nodeStats.getString("PatientID");
                                     Log.v("patientid",sSDR);
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

but its not converting to jsonobject.

i need to get all values from here..
Posted
Updated 16-Jun-14 3:41am
v2

1 solution

The [...] indicate that value is an array type and not object.

Try changing this:
JSONObject nodeStats = nodeRoot.getJSONObject("value");

To this:
JSONArray nodeStats = nodeRoot.getJSONArray("value");

Remember that you now must loop over the nodeStats array.

Good luck!
 
Share this answer
 
Comments
mekalareddy 28-May-14 5:02am    
its string how can i change

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900