-1

Any help? This has been driving me nuts!!! I have taken an xml file and dumped the namespaces and have a great array but for the life of me can't figure out how to work with the json to get variable for:

{
    "ListMatchingProductsResponse": {
        "ListMatchingProductsResult": {
            "Products": {
                "Product": [
                    {
                        "Identifiers": {
                            "MarketplaceASIN": {
                                "MarketplaceId": "ATVPDKIKX0DER",
                                "ASIN": "B000WTLJIQ"
                            }
                        },
                        "AttributeSets": [],
                        "Relationships": {
                            "VariationParent": {
                                "Identifiers": {
                                    "MarketplaceASIN": {
                                        "MarketplaceId": "ATVPDKIKX0DER",
                                        "ASIN": "**B00FM1EXEQ**"
                                    }
                                }
                            }
                        },
                        "SalesRankings": {
                            "SalesRank": [
                                {
                                    "ProductCategoryId": "pet_products_display_on_website",
                                    "Rank": "115236"
                                },
                                {
                                    "ProductCategoryId": "**5769007011**",
                                    "Rank": "362"
                                }
                            ]
                        }
                    },
                    {
                        "Identifiers": {
                            "MarketplaceASIN": {
                                "MarketplaceId": "ATVPDKIKX0DER",
                                "ASIN": "B00NDY7666"
                            }
                        },
                        "AttributeSets": [],
                        "Relationships": [],
                        "SalesRankings": []
                    },
                    {
                        "Identifiers": {
                            "MarketplaceASIN": {
                                "MarketplaceId": "ATVPDKIKX0DER",
                                "ASIN": "B009YJ3JSI"
                            }
                        },
                        "AttributeSets": [],
                        "Relationships": {
                            "VariationParent": {
                                "Identifiers": {
                                    "MarketplaceASIN": {
                                        "MarketplaceId": "ATVPDKIKX0DER",
                                        "ASIN": "B00P3MYXHQ"
                                    }
                                }
                            }
                        },
                        "SalesRankings": {
                            "SalesRank": [
                                {
                                    "ProductCategoryId": "pet_products_display_on_website",
                                    "Rank": "180220"
                                },
                                {
                                    "ProductCategoryId": "3203999011",
                                    "Rank": "8108"
                                }
                            ]
                        }
                    },
                    {
                        "Identifiers": {
                            "MarketplaceASIN": {
                                "MarketplaceId": "ATVPDKIKX0DER",
                                "ASIN": "B00ARCFLFA"
                            }
                        },
                        "AttributeSets": [],
                        "Relationships": [],
                        "SalesRankings": {
                            "SalesRank": [
                                {
                                    "ProductCategoryId": "pet_products_display_on_website",
                                    "Rank": "297848"
                                },
                                {
                                    "ProductCategoryId": "5769009011",
                                    "Rank": "879"
                                }
                            ]
                        }
                    },
                    {
                        "Identifiers": {
                            "MarketplaceASIN": {
                                "MarketplaceId": "ATVPDKIKX0DER",
                                "ASIN": "B00DJAEX6U"
                            }
                        },
                        "AttributeSets": [],
                        "Relationships": {
                            "VariationParent": {
                                "Identifiers": {
                                    "MarketplaceASIN": {
                                        "MarketplaceId": "ATVPDKIKX0DER",
                                        "ASIN": "B0091TK10K"
                                    }
                                }
                            }
                        },
                        "SalesRankings": []
                    },
                    {
                        "Identifiers": {
                            "MarketplaceASIN": {
                                "MarketplaceId": "ATVPDKIKX0DER",
                                "ASIN": "B00FC7ALY6"
                            }
                        },
                        "AttributeSets": [],
                        "Relationships": [],
                        "SalesRankings": []
                    }
                ]
            }
        },
        "ResponseMetadata": {
            "RequestId": "9d9da767-ffc5-4eb3-ab95-8f9e91dc7af2"
        }
    }
}

2 Answers2

0

use json_decode() and it will turn your json into an object.

$json = json_decode(<json_string));
Erik Flitman
  • 163
  • 4
0

Use json_decode() to return an array then use foreach loop

  $result = json_decode($yourJSON);

  foreach($result as $key => $val){
    //do something here
    echo 'Key: ' .$key . ' Value: ' . $val;
  }
aldrin27
  • 3,407
  • 3
  • 29
  • 43