dongzai3917 2016-01-15 08:26
浏览 69
已采纳

使用PHP解析字符串中的问题

Here is the response that I am receiving.

{  
    "StartTime":"2016-01-15T03:22:33.109787-05:00",
    "EndTime":"2016-01-15T03:22:34.2504378-05:00",
    "queryController":{  
        "TotalRecords":8355,
        "PageNumber":1,
        "PageSize":8,
        "DataFilters":[  

        ],
        "PropertyListing":[  
            {  
                "EntityName":"Product",
                "PropertyName":"IXOneId"
            },
            {  
                "EntityName":null,
                "PropertyName":"UPC12"
            }
        ],
        "EntityName":"QueryController"
    },
    "Products":[  
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1080",
            "UPC12":"037014000245"
        },
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1090",
            "UPC12":"747599617003"
        },
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1079",
            "UPC12":"024182001822"
        },
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1102",
            "UPC12":"745158300519"
        },
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1077",
            "UPC12":"024182001891"
        },
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1148",
            "UPC12":"039978003645"
        },
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1110",
            "UPC12":"070670005759"
        },
        {  
            "EntityName":"Product",
            "IXOneId":"SNL1083",
            "UPC12":"037014000290"
        }
    ],
    "ResponseMessages":null,
    "EntityName":"ProductSearchReturn"
}

I want to get the values of IXOneId & UPC12 values of that for all the records and wants to display it on my page. How to get this with help of PHP ? Kinda stuck on that. Help will be appreciated.

  • 写回答

3条回答 默认 最新

  • doushoubu5360 2016-01-15 09:21
    关注

    Assuming the following variable $string contains your sample json string.
    Decode using json decode and iterate over the inner Products array.

    $json = json_decode($string);
    
    foreach($json->Products as $product){
        print $product->IXOneId . ' ' . $product->UPC12 . PHP_EOL;
    }
    

    Will output

    SNL1080 037014000245
    SNL1090 747599617003
    SNL1079 024182001822
    SNL1102 745158300519
    SNL1077 024182001891
    SNL1148 039978003645
    SNL1110 070670005759
    SNL1083 037014000290
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大