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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?