http://blog.sina.com.cn/s/blog_4ba0876e0100l8ir.html
去除php的warning显示
php可以不经声明直接使用变量, 做久了自然养成变量随写随用的习惯, 不过在WAMP环境默认设置下这样的页面在浏览时会显示警告, 比如"Notice: Use of undefined constant
最常用的解决方法是修改php.ini配置文件: error_reporting = E_ALL & ~E_NOTICE. 或者可以试着每个文件头部加上error_reporting(0);
http://3y.uu456.com/bp-302dq34e6edb6f1aff001f7e-1.html
ThedifferenceisthatoptSt;这个是在stackoverflow上面看到的,m;
The difference is that optString returns the empty string ("") if the key you specify doesn't exist.getString on the other hand throws a JSONException. Use getString if it's an error for the data to be missing, or optString if you're not sure if it will be there.
这个是在stackoverflow上面看到的,mark一下,简单来说就是optString会在得不到你想要的值时候返回空字符串”“,而getString会抛出异常。
三亿文库3y.uu456.com包含各类专业文献、中学教育、生活休闲娱乐、外语学习资料、高等教育、行业资料、各类资格考试、幼儿教育、小学教育、应用写作文书、19JSON中getString() 和optString()等内容
以下是android程序中解析json的部分
JSONArray jsonarr = new JSONArray(json.getString("user"));
userArr = new UserBase[jsonarr.length()];
for (int i = 0; i < jsonarr.length(); i++) {
userArr[i] = new UserBase();
userArr[i].userNo = jsonarr.getJSONObject(i).getString(
"user_No");
userArr[i].userName = jsonarr.getJSONObject(i).getString(
"user_name");
userArr[i].userSex = Integer.parseInt(jsonarr
.getJSONObject(i).getString("user_sex"));
userArr[i].userEmail = jsonarr.getJSONObject(i).getString(
"user_email");
userArr[i].userPassword = jsonarr.getJSONObject(i)
.getString("user_pwd");
}
php源码部分:
$response["user"]=array();
$row=mysql_fetch_array($result);
$user=array();
$user["user_No"] = $row["userNo"];
$user["user_name"] = $row["userName"];
$user["user_sex"] = $row["userSex"];
$user["user_email"] = $row["userEmail"];
$user["user_pwd"] = $row["userPassword"];
array_push($response["user"], $user);
$response["success"]=1;
$response["message"]="successful!!!rows=".$rows;
//$response["users"]=array();
echo json_encode($response);