0

这是我的 json 输出:

{"Please enter valid mobile no!!":1}

这是我的代码:

jArray = new JSONArray(results);
JSONObject json_data=null;
json_data = jArray.getJSONObject(0);
int result=json_data.getInt("1"); // get the json string name
System.out.println("message "+result);

但它给了我一个例外。

这是我的 php 代码:-

$arr = array("Please enter valid mobile no!!"=>1); 
echo json_encode($arr); exit

如何检索值?

4

1 回答 1

0

The key in your example is "Please enter valid mobile no!!" So int result=json_data.getInt("Please enter valid mobile no!!"); should return 1, not the other way around.

If you want to use 1 as a key you should use:

    String result=json_data.getString("1");  //get the String with key 1

php code:

    $arr = array(1 => "Please enter valid mobile no!!");  //key => value
于 2013-02-21T08:12:37.097 回答