Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

html - How to implement JSON-LD?

I’ve been reading about JSON-LD today and I understand its purpose, format, and that I can put it in a script tag; however, I don’t understand the following:

  1. Where can this data reside other than in a script tag for a website? I've been expecting to find JSON-LD content in either script tags or included .json files when I view the page source of websites that say they use JSON-LD, but since I haven't seen any of this, it leads me to believe it must be accessible in a different location.

  2. How is this collection of information usually constructed for larger websites?

  3. How do other sites find the JSON-LD files, objects, or data to use that information?

It would be really great to see an example in the wild.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In HTML5, the script element can be used as data block:

When used to include data blocks (as opposed to scripts), the data must be embedded inline, the format of the data must be given using the type attribute, the src attribute must not be specified, and the contents of the script element must conform to the requirements defined for the format used.

So a script element containing JSON-LD could look like this:

<script type="application/ld+json">
    {
     "@context": "http://example.com",
     "@type": "Example"
    }
</script>

You may place the script element(s) in the head and/or in the body.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...