相关疑难解决方法(0)

为什么json_encode会返回一个空字符串

我有一个简单的PHP结构,有3个嵌套数组.

我没有使用特定的对象,我自己构建了带有2个嵌套循环的数组.

这是我想要转换为Json的数组的var_dump示例.

array (size=2)
  'tram B' => 
    array (size=2)
      0 => 
        array (size=3)
          'name' => string 'Ile Verte' (length=9)
          'distance' => int 298
          'stationID' => int 762
      1 => 
        array (size=3)
          'name' => string 'La Tronche Hôpital' (length=18)
          'distance' => int 425
          'stationID' => int 771
  16 => 
    array (size=4)
      0 => 
        array (size=3)
          'name' => string 'Bastille' (length=8)
          'distance' => int 531
          'stationID' => int 397
      1 => 
        array (size=3)
          'name' => string 'Xavier Jouvin' (length=13)
          'distance' => …
Run Code Online (Sandbox Code Playgroud)

php json

98
推荐指数
7
解决办法
8万
查看次数

Response内容必须是实现__toString(),\"boolean \"的字符串或对象."

我正在尝试使用渲染的View返回Response::json但是我收到此错误:

The Response content must be a string or object implementing __toString(), \"boolean\" given."
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

$posts = Post::where( ... )->orderBy( ... )->get();
$data['posts'] = View::make("posts.partials.loadHome")->with("posts", $posts)->render();
$data['msg'] = "ok";

return Response::json($data);
Run Code Online (Sandbox Code Playgroud)

如果var_dump($data)我得到这个:

<pre class='xdebug-var-dump' dir='ltr'>
<b>array</b> <i>(size=2)</i>
  'posts' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'&lt;div class=&quot;post postGrid&quot; data-id=&quot;1864&quot;&gt;&#10; &lt;a target=&#39;_blank&#39; href=&quot;http://objavi.net/posts/1864&quot;&gt;&lt;img src=&quot;http://objavi.net/&quot; id=&quot;imgWrap&quot; data-original=&quot;/thumbs/YAo4wFzIpl76.jpg&quot; class=&quot;lazy&quot; alt=&quot;Deset manje poznatih ?injenica o Jozefu Staljinu&quot;&gt;&lt;/a&gt;&#10;  &#10;   &lt;div id=&quot;bodyPreview&quot;&gt;&#10;     &#10;       &lt;a target=&#39;_blank&#39; href=&quot;http://objavi.net/posts/1864&quot;&gt;&lt;h1 class=&quot;previewTitle&quot;&gt;Deset manje poznatih ?injenica o Jozefu Staljinu&lt;/h1&gt;&lt;/a&gt;&#10;&#10;     &lt;h3 id=&quot;postInfo&quot;&gt;&#10; …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-4

23
推荐指数
4
解决办法
4万
查看次数

标签 统计

php ×2

json ×1

laravel ×1

laravel-4 ×1