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 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错