dongnue4923 2017-02-24 05:07
浏览 59

json_decode错误,无法运行foreach循环

I am in a trouble with API development with Laravel 5.3.

My application is a shopping app, after verify the cart need to submit the cart details and customer details to server through an API.

Android PostData in LogCat

{"customer_id":378,"customer_shipping_id":487,"order_amount":13.5,"cashback":0,"store_id":134,"delivery_amount":0.0,"currency":133,"coupon":"","product_array":"[\"{\\\"product_id\\\":933,\\\"product_quantity\\\":1,\\\"product_name\\\":\\\"7up Cherry 330ml\\\",\\\"total\\\":3.5}\",\"{\\\"product_id\\\":722,\\\"product_quantity\\\":1,\\\"product_name\\\":\\\"A&W Root Beer Aged Vanilla 355ml\\\",\\\"total\\\":10.0}\"]"}

Laravel Controller

  $customer_id     = Input::get('customer_id');
  $shipping_id     = Input::get('customer_shipping_id');
  $amount          = Input::get('order_amount');
  $cashback        = Input::get('cashback');
  $store_id        = Input::get('store_id');
  $delivery_charge = Input::get('delivery_amount');
  $coupon          = Input::get('coupon');
  $currency_id     = Input::get('currency');
  $product_array   = json_decode(Input::get('product_array'));

  foreach ($product_array as $item) {
    $res[]= $item['product_id'];
  }
  $response= [

        'status' => 200,
        'result' => [
          'product_ids' => $res
        ]
    ];
  return $response;

I can get all keys except product_array and not able to loop with the foreach.

var_dump(Input::get('product_array'));

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥15 Oracle触发器记录修改前后的字段值
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题