杂七杂八学习日记2015-5-27

http://blog.sina.com.cn/s/blog_4ba0876e0100l8ir.html


去除php的warning显示

 

php可以不经声明直接使用变量, 做久了自然养成变量随写随用的习惯, 不过在WAMP环境默认设置下这样的页面在浏览时会显示警告, 比如"Notice: Use of undefined constant xxxx - assumed 'xxxx' in xxxxxx.php on line xxx"..

最常用的解决方法是修改php.ini配置文件: error_reporting = E_ALL & ~E_NOTICE. 或者可以试着每个文件头部加上error_reporting(0);


http://3y.uu456.com/bp-302dq34e6edb6f1aff001f7e-1.html

JSON中getString() 和optString()

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);






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值