草庐IT

php - 根据客户端发送 HTML 或 JSON 响应

我有一个Laravel应用程序,其中包含Eloquent实体及其各自的RESTfulresourcecontrollers,如下所示:模型classEntityextendsEloquent{...}ControllerclassEntityContoller{publicfunctionindex(){Entity$entities=Entity::all();returnview('entity.index',compact($entities));}...//Andmanymorerouteslikethat}现在我正在构建一个android应用程序,而不是返回View,我需要数

php - 以html表格格式显示json数据

嘿伙计,我是编程新手。我想使用jquery在HTML表中显示Json数据。输出来自服务器:{"status":1,"insert":1,"data":[{"id":"1","name":"Jatin","email":"jatin@122.d","status":"1"},{"id":"2","name":"Shubham","email":"jatin@122.d","status":"1"},{"id":"3","name":"Aneh","email":"jatin@122.d","status":"1"},{"id":"52","name":"php","email":"rau

php - 按月对 PHP JSON 数组进行排序

我正在尝试按MONTH名称缩短数组。[{"order_id":34,"user_id":17,"sum":65000,"month":"May"},{"order_id":32,"user_id":19,"sum":15000,"month":"July"},{"order_id":29,"user_id":1,"sum":20000,"month":"April"}]有什么办法可以快速解决这个问题吗?我需要名称格式的月份。我希望得到如下结果。[{"order_id":29,"user_id":1,"sum":20000,"month":"April"},{"order_id":34,

php - Laravel - 当集合作为 JSON 返回时访问器不起作用

我正在使用Laravel为VueJS前端SPA构建API。我需要接受日期并将其返回为“d-m-Y”,而不是存储在数据库中的“Y-m-d”。数据突变器工作正常,我设法在给定日期正确保存它,但是当我运行时:$active=Announcement::where('group_id',$this->user->group_id)->where('dateTo','>=',Carbon::today())->get();returnresponse()->json($active);我正在获取纯数据库数据,而不是对其进行格式化。例如,我有一个需要格式化的dateTo字段:publicfunct

php - 如何使用 return as json laravel 进行分页

我想创建一个返回为json的分页,但出现如下错误ErrorExceptioninMacroable.phpline74:Methodlinksdoesnotexist.这里是我的Controller代码publicfunctiongetcustomer($id){$customer=Customer::find($id)->paginate(5);returnresponse()->json([$customer],200);}这是我的Blade代码{{$customer->links('vendor.pagination.pagination')}}如何使用jsonresponse(

PHP json_decode 无法正常工作

我正在尝试使用PHP的json_decode函数从json对象中获取特定值。示例代码如下:foreach($streamsas&$i){$chan="http://api.justin.tv/api/stream/list.json?channel=".$i;$json=file_get_contents($chan);//Turnsthegatheredfileinformationintoastringforsearchingpurposes.echo$json."Endofjsonvariable.";$exist=strpos($json,'name');//Searchthe

php - 使用 PHP 解码 Microsoft 翻译器 API 的 JSON 输出

这个问题似乎特定于microsofttranslator.com所以请...任何答案,如果您可以针对它进行测试...使用以下网址进行翻译:http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray..我通过cURL发送了一些奇妙的论点,并得到了以下结果:[{"From":"en","OriginalTextSentenceLengths":[13],"TranslatedText":"我是最好的","TranslatedTextSentenceLengths":[5]},{"From":"en","OriginalText

php - 从键上的 json 编码字符串中删除双引号

我有一个json_encoded数组,这很好。在从函数调用返回时,我需要去除json字符串所有键上的双引号。我将如何着手执行此操作并成功返回它?谢谢!我很抱歉,这里是json代码的片段:{"start_date":"2011-01-0109:00","end_date":"2011-01-0110:00","text":"test"}只是为了添加更多信息:我将通过AJAX请求检索JSON,所以如果它更容易,我愿意接受关于如何在javascript端执行此操作的想法。 最佳答案 编辑根据anubhava的评论$str='{"start

php - json_encode 在我的 php 中没有任何作用

我有这个小代码,我知道我从数据库中收到了很好的结果,因为我做了一些print_r并且工作正常://buildquerySQL$query=$this->select()->where('numBedrooms=?',$numBedrooms)->where('type=?',$type)->where('state=?',$state)->limit(8);//8rows,withanoffsetof$recent_page*8-8//executequerySQL$rows=$this->fetchAll($query);//encodejson$var=json_encode($r

php - 如何在 json 或 javascript 或 jquery 中使用反斜杠读取值

我需要使用jQueryAjax将值(Windows路径)传输到json,以便将值抛出或解码到PHP脚本,但它无法读取json中带有反斜杠的值。必须将其传输为带有反斜杠的整个路径的json值。我的示例代码:/*==========================================================================*/varfile_name="C:\WINDOWS\Temp\phpABD.tmp";varjsonSearchContent="{\"file_name\":\""+file_name+"\"}";$.ajax({type:"POS