0

我正在开发一个使用restful WCF与数据库通信的android应用程序。
我的 WCF 代码是:

 public string GetData(string id)
        {
            UsersBLL locbll = new UsersBLL();
            int locationid;
            if (int.TryParse(id,out locationid))
            {
                loc = locbll.FindById(locationid);
                var json = new JArray( new JObject(new JProperty("Name",loc.MobileNo),new JProperty("ID",loc.ID)));
                return json.ToString();
            }
            return null;
        }

返回的数据就像 [ { "Name": "0120800281", "ID": 4 } ] 我的代码应用程序一样

DefaultHttpClient httpclien = new DefaultHttpClient();
            URI uri = new URI("http://10.0.2.2:1056/Service1.svc");
            HttpGet httpget = new HttpGet(uri + "/getdata/"
                    + evEmployeeId.getText());
            httpget.setHeader("Accept", "application/json");
            httpget.setHeader("Content-type", "application/json; charset=utf-8");
            HttpResponse response = httpclien.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity.getContentLength() != 0) {
                BufferedReader employeeReader = new BufferedReader(
                        new InputStreamReader(response.getEntity().getContent()));
                // char[] buffer = new char[(int)
                // response.getEntity().getContentLength()];
                // employeeReader.read(buffer);
                // employeeReader.close();
                String line = employeeReader.readLine();

我想使用 json 解析返回的数据

4

1 回答 1

0

这应该可以帮助您:

        JSONArray jArr = new JSONArray("Your String Json Data");
        JSONObject jobAll = jArr.getJSONObject(0);
        String object =jobAll.getString("Name");
于 2013-09-18T09:21:18.797 回答