草庐IT

php - 为什么将空白字符串的 json_encode 添加到数组中?

我在PHP5.6上遇到过这种行为(在PHP5.4到7.0中也是相同的)。$note=newSimpleXMLElement('');$note->addChild("string0",'justastring');$note->addChild("string1","abc\n\n\n");$note->addChild("string2","\tdef");$note->addChild("string3","\n\n\n");$note->addChild("string4","\t\n");$json=json_encode($note,JSON_PRETTY_PRINT);pr

php - json_decode($var) 和 (object)json_decode($var, true) 的区别

json_decode($var)和(object)json_decode($var,true)有区别吗?当最近在Joomlavirutemart中处理某段代码时,我遇到了一个困惑的情况。Virtumart对其cartObject使用(object)json_decode($var,true),如果我将其更改为简单的json_decode($var),它之后会显示一些错误。在进一步调试时,我发现购物车结构为:stdClassObject([cartProductsData]=>Array()[vendorId]=>0[automaticSelectedShipment]=>[autom

php - 使用 PHP 从 .json 文件中删除 JSON 记录

我有一个像这样的json文件:[["{\"id\":1474721566304,\"name\":\"GGG\",\"brand\":\"GG\",\"price\":\"3\"}"],["{\"id\":1474721570904,\"name\":\"GGGH\",\"brand\":\"GGH\",\"price\":\"4\"}"],["{\"id\":1474721574188,\"name\":\"GGGH\",\"brand\":\"GGHH\",\"price\":\"5\"}"]]我想做的是通过它的id从中删除一条记录。为此,我有以下PHP代码:我从这段代码中得到的是

php - 如何从 PHP 中获取远程 JSON 或 XML API 数据并将返回对象分配为 PHP 变量?

我在做什么:我正在用PHP编写自定义程序,它通过API从在线LMS服务中提取数据。现在,我正在尝试实现可用的单点登录功能。程序的这一部分需要在单击按钮时(通过js或phpPOST或?)向API执行GET请求,并最终将用户浏览器重定向到API响应中提供的URL。API允许选择XML或JSON响应,我更愿意使用JSON,但如果需要的话,我会凑合使用XML。来自关于发出请求的API文档:Allrequestslistedinthisdocumentshouldcontainacontent-type(XMLorJSON)intherequestheaderandbeprefixedwitht

将JSON值添加到列表中

我想通过我的JSON文件迭代,并在列表中添加两个值。从理论上讲,我希望有一个嵌套列表为:ips=[["custom3","modemId"],["custom3","modemId"]]等等。我的JSON文件具有每个自定义3和调制数值的171个。因此,从理论上讲,我的嵌套列表将包含171个列表。我很难将这些值添加到一个列表中,在其中我想将每个列表共同附加到创建171个列表。json1=open('C:\\Users\\'+comp_name+'\\Documents\\ProgrammingProjects\\Python\\PythonFirmwareScript\\curl\\src\\o

php - 为什么在 ajax 请求中使用 JSON 或者为什么不使用

我想知道什么时候通过ajax以json数组的形式从php页面中提取数据是合理的。假设我有这段代码:$.ajax({type:"get",url:"assets/update_cart_user_fstore.php",data:up,cache:false,success:function(r){$(#item).html(r);},});在PHP页面中我回显了一个变量$hello="Iamcode!";echo$hello;还有JSON$.ajax({type:"get",url:"assets/update_cart_user_fstore.php",data:up,cache:f

javascript - 将 json 数据从 php 返回到 ajax

我正在尝试从php获取一个json对象,以便我可以在ajax中使用它。这是我的ajax代码:$.ajax({type:'get',url:eventsListPath,dataType:"json",data:{},success:function(data){$('#eventInformation').html(data.table);alert(data.table);}});还有我的PHP:$obj->table="hey";echojson_encode($obj,JSON_UNESCAPED_SLASHES);但是线alert(data.table);返回“undefine

php - 空的 services.json 文件正在破坏站点

我明白了Whoops,lookslikesomethingwentwrong.在我的生产服务器上。突然之间,artisan命令都不起作用了。我在/bootstrap/compiled.php:4496上遇到错误。删除compiled.php后,我收到相同的消息"array_merge():Argument#2isnotanarray"in/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository".php:188.我的services.json文件是空的,当我尝试使用PHPartisancache:cle

php - json类型字段的Laravel数据库在返回值时添加“

我已经阅读了Laravel5文档,我看到它支持数据库中的json类型字段,但我注意到了非常奇怪的行为。这是我的table:Schema::create('subjects',function($table){$table->increments('id');$table->string('name',100);$table->integer('ects');$table->json('studies');//thisismyjsontypefield$table->date('created_at');$table->date('updated_at');});然后我为数据库播种:Su

php - yii2 以其他名称将 ActiveRecord 属性作为 JSON 返回

当我选择ActiveRecord时$models=Model::find()->select(['someothername'=>'name'])->all();并将这个“someothername”作为公共(public)属性添加到模型中,然后我可以访问它$model->someothername但是现在我需要用JSON返回这个字段\Yii::$app->response->format=\yii\web\Response::FORMAT_JSON;return$models;我该怎么做?我应该在属性中添加“someothername”吗? 最佳答案