[英]problems with JSON Decode & strings
having a bit of an issue here. 在这里有一个问题。 I'm passing data over an AJAX command to my php script.
我通过AJAX命令将数据传递给我的php脚本。 The data travels across fine.
数据传输良好。
Print_r 打印_r
Array
( [0] => stdClass Object
( [Loc] => Main Door
[Module] => O2
[Dect] => O2
[GasDec] => O2
[ScB4] =>
[ScA4] =>
[A1] =>
[A2] =>
[CalGas] =>
[CalGasA] =>
[Factor] =>
[ZB4] =>
[ZA4] =>
[CalB4] =>
[CalA4] =>
[CHNoID] => 5
[JobID] => 3 )
)
I can use The following method just fine but when i use option two it doesn't like it due to this error message: 我可以使用以下方法很好,但是当使用选项二时,由于此错误消息,它不喜欢它:
Catchable fatal error: Object of class stdClass could not be converted to string 可捕获的致命错误:无法将类stdClass的对象转换为字符串
Methods 方法
//Method one
echo "JobID: " . $comm[0]->JobID; // result: 3
//Method two
echo "JobID: '$comm[0]->JobID'"; // get error message
The reason im using method two is so I can pass the information into mysql. 我使用方法二的原因是我可以将信息传递到mysql中。 If anyone knows something i'm missing or it can't be done or even a easier way.
如果有人知道我所缺少的东西,或者无法完成甚至是更简单的方法。 please say.
请说。
Thanks. 谢谢。
EDIT 编辑
Query 询问
$sql = "INSERT INTO
calinfo (Sbefore, Safter, A1, A2, CalGas, Factor, Zbefore, Zafter, Cbefore, Cafter, SysInfoID)
VALUES
('$comm[$i]->ScB4', '$comm[$i]->ScA4', '$comm[$i]->A1', '$comm[$i]->A2', '$comm[$i]->CalGasA', '$comm[$i]->Factor', '$comm[$i]->ZB4', '$comm[$i]->ZA4', '$comm[$i]->CalB4', '$comm[$i]->CalA4', '$comm[$i]->CHNoID');";
$sql .= "UPDATE
jobs
SET
CompletedBy = $tech
WHERE JobID = '$comm[$i]->JobID';"; //<-- when i try the method of "WHERE JobID = ".$comm[$i]->JobID.";"; it doesnt like it...
You may need to do as 您可能需要这样做
echo "JobID: '{$comm[0]->JobID}'";
So in the query u can use it as where some_col = '{$comm[0]->JobID}'
因此,在查询中,您可以将其用作
where some_col = '{$comm[0]->JobID}'
Try like this 这样尝试
$sql .= "UPDATE
jobs
SET
CompletedBy = $tech
WHERE JobID = '".$comm[$i]->JobID."'";
As the error message saies, the return cannot be converted to fit into a string directly. 正如错误消息所说,返回值不能直接转换为适合字符串的形式。
echo sprintf( "JobID: '%s'",$comm[0]->JobID);
or 要么
echo "JobID: '{$comm[0]->JobID}'";
or 要么
echo "JobID: '" . $comm[0]->JobID . "'";
should do the trick 应该可以
Simple double quotes won't interpolate complex combinations like this. 简单的双引号不会插入像这样的复杂组合。 You need to use curly braces to achieve this, eg
echo "JobID: {$comm[0]->JobID}";
您需要使用花括号将其实现,例如
echo "JobID: {$comm[0]->JobID}";
. 。
You could however also use printf
, eg printf("JobID: %s", $comm[0]->JobID);
但是,您也可以使用
printf
,例如printf("JobID: %s", $comm[0]->JobID);
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.