Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse ld+json wrong #65

Open
valeriy-efimov opened this issue Apr 11, 2021 · 2 comments
Open

Parse ld+json wrong #65

valeriy-efimov opened this issue Apr 11, 2021 · 2 comments

Comments

@valeriy-efimov
Copy link

Hi i have like this json

  {
    "@context": "https://schema.org/",
    "@type": "Product",
    "name": "Extra",
    "image": "https://www..jpg",
    "category": [
      "category",
    ],
    "description": "This Stun",
    "SKU": "11111",
    "Offers": {
      "@type": "Offer",
      "priceCurrency": "GBP",
      "price": "509.99",
      "itemcondition": "http://schema.org/NewCondition",
      "availability": "https://schema.org/PreOrder",
      "url": "https://www."
    },
  }

I try to get offers but immutableName wrong and i get error OutOfBoundsException|
image

if i change manually Offers to offers all works
image

change json i cant it external and use like this i think bad idea str_replace("Offers", "offers", "json") because json on HTML page

What else can I do?

@rvanlaak
Copy link
Collaborator

rvanlaak commented May 8, 2021

Can you provide us with a code snippet that demonstrates the problem?

@valeriy-efimov
Copy link
Author

@rvanlaak

use Jkphl\Micrometa\Ports\Parser;
$html = "
  {
    "@context": "https://schema.org/",
    "@type": "Product",
    "name": "Extra",
    "image": "https://www..jpg",
    "category": [
      "category",
    ],
    "description": "This Stun",
    "SKU": "11111",
    "Offers": {
      "@type": "Offer",
      "priceCurrency": "GBP",
      "price": "509.99",
      "itemcondition": "http://schema.org/NewCondition",
      "availability": "https://schema.org/PreOrder",
      "url": "https://www."
    },
  }
"

$url = 'https://example.com';
$parser = new Parser();
        $parsed = $parser($url, $html);
        
              foreach ($parsed->getItems() as $item) {
            /** @var \Jkphl\Micrometa\Domain\Item\Iri[] $types */
            $types = $item->getType();
            foreach ($types as $type) {
                if ($type->name === 'Product') {
                   
                   $offers = $this->getPropertyValue($item, 'offers'); 
                }
            }
        }  
        

        

Cant find offers because https://schema.org/offers lover case and parser not correct set immutableName and got error OutOfBoundsException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants