如何在android中获取Integer Json值

时间:2016-11-07 14:13:52

标签: android web-services

在我的机器人中我得到了Json的回复,但我想在android.In中得到整数变量的Json值。在Jsonarray我有了我的价值。所以请帮我这个。我在" MenuNameFromAndroid"中返回了整数值。功能

protected class AsyncMenuname extends
                AsyncTask<MenunameSendFrom, JSONObject, JSONObject> {

            JSONObject jsonObj = null;

            @Override
            protected JSONObject doInBackground(MenunameSendFrom... params) {

                RestAPI api = new RestAPI();

                try {

                    jsonObj = api.MenuNameFromAndroid(params[0].getMenuname());

                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    Log.d("AsyncCreateUser", e.getMessage());
                }
                return jsonObj;
            }

            @Override
            protected void onPostExecute(JSONObject objects) {

                try {

                    //JSONArray jsonArray = objects.getJSONArray("Value");

                    String string = null;
                    JSONArray a = objects.getJSONArray("Value");


                } catch (Exception e) {
                    e.printStackTrace();
                }

                Toast.makeText(TwoList.this, "Successfully inserted...", Toast.LENGTH_LONG).show();

            }


        }

在这个函数中,我得到了JSON对象的响应

 public JSONObject MenuNameFromAndroid(String getMenuname) throws Exception {
        JSONObject result = null;
        JSONObject o = new JSONObject();
        JSONObject p = new JSONObject();
        o.put("interface","RestAPI");
        o.put("method", "MenuNameFromAndroid");
        p.put("getMenuname",mapObject(getMenuname));
        o.put("parameters", p);
        String s = o.toString();
        String r = load(s);
        result = new JSONObject(r);
        return result;
    }



And This is function that I have return float value. That float value i want to get in android
     float menuId = 0;
            public float MenuNameFromAndroid(string getMenuname)
            {
                if (dbConnection.State.ToString() == "Closed")
                {
                    dbConnection.Open();
                }
                menuId = db.getDb_Value("select menu_id From menu where m_name='" + getMenuname + "'");

                dbConnection.Close();
                return menuId;

            }

0 个答案:

没有答案