json - JSON 到 JSON-LD (+ Schema.org) 的转换
问题描述
以下是我在 JS Ajax 调用请求中获得的示例 JSON 数据。如何将其转换为 JSON-LD 并附加到head
标签?
[
{
"resort": "100",
"resortCategory": "BEST",
"resortDistanceMiles": 37.1,
"resortDistanceKms": 59.7,
"currencySymbol": "$",
"resortAvailable": "AVAILABLE",
"resortSummary": {
"resort": "19100",
"latitude": 29.460099,
"longitude": -90.321457,
"timeZone": "America/New_York",
"name": "Best Western Isabelle Court",
"description": "Welcome to other!",
"address1": "17026 Highway 3235",
"city": "Galliano",
"phoneNumber": "+1 985-325-3800",
"faxNumber": "985/325-3808",
"postalCode": "70354",
"stateCode": "LA",
"state": "Louisiana",
"countryCode": "US",
"country": "United States",
"currencyCode": "USD",
"currencyDescription": "U.S. DOLLARS",
"resortCategory": "BEST",
"checkOutNoticeTime": "11:00 a.m.",
"checkInNoticeTime": "3:00 p.m.",
"propertyType": "INTOWN",
"prearrivalEmail": true
},
"searchableAmenities": [
{
"text": "Air Conditioning at property",
"attributeValueCode": "AIR CONDITIONING"
},
{
"text": "AIR CONDITIONED",
"attributeValueCode": "AIRCON"
},
{
"text": "AM/FM alarm clock",
"attributeValueCode": "ALRMCK"
},
{
"text": "Beach on premises or nearby",
"attributeValueCode": "BEACH"
},
{
"text": "Best Western",
"attributeValueCode": "BEST WESTERN"
},
{
"text": "Complimentary Breakfast",
"attributeValueCode": "BRKFST COMP"
},
{
"text": "Business center on premises (fax/copier/computer etc)",
"attributeValueCode": "BUSCTR"
},
{
"text": "Cable or satellite TV on premises.",
"attributeValueCode": "CABLE TV"
},
{
"text": "Guests that are 12 years old and younger are considered children.",
"attributeValueCode": "CHILD 12"
},
{
"text": "Coffee makers available in room.",
"attributeValueCode": "COFFEE MAKERS"
},
{
"text": "RJ-11 Modular/dataports phone jacks available in room.",
"attributeValueCode": "DATA PORT"
},
{
"text": "24 hour front desk",
"attributeValueCode": "DESK24"
},
{
"text": "Physically challenged facilities available",
"attributeValueCode": "DISABL"
},
{
"text": "Property has elevator access to floors.",
"attributeValueCode": "ELEVATOR"
},
{
"text": "Express checkout available",
"attributeValueCode": "EXCKOT"
},
{
"text": "Exercise facilities available on premises.",
"attributeValueCode": "EXERCISE"
},
{
"text": "Free parking available.",
"attributeValueCode": "FPRKNG"
},
{
"text": "Free local telephone calls",
"attributeValueCode": "FRCLLS"
},
{
"text": "Free Breakfast Offered at Property",
"attributeValueCode": "FREE BREAKFAST"
},
{
"text": "Free continental breakfast - Includes juice, bread or sweet roll, and coffee.",
"attributeValueCode": "FREE CONT. BRKFST"
},
{
"text": "All Guest Rooms are Hardwired or Wireless",
"attributeValueCode": "FRWL-HW-GUESTRM"
},
{
"text": "Free Wireless in Public Areas and Guest Rooms",
"attributeValueCode": "FRWL-PUBGUEST"
},
{
"text": "In-room hair dryers.",
"attributeValueCode": "HAIR DRYERS"
},
{
"text": "High Speed Internet Access",
"attributeValueCode": "HIGH SPEED"
},
{
"text": "Higher rates may apply for special events and holidays.",
"attributeValueCode": "HOLIDAY/EVENT RATES"
},
{
"text": "Inside Corridors",
"attributeValueCode": "INSIDE-CORR"
},
{
"text": "Irons and ironing boards available in room.",
"attributeValueCode": "IRONS/IRONING BOARDS"
},
{
"text": "Microwave oven in room.",
"attributeValueCode": "MICROWAVE"
},
{
"text": "Multi-lingual staff.",
"attributeValueCode": "MULTI-LINGUAL"
},
{
"text": "No pets allowed.",
"attributeValueCode": "NO PETS"
},
{
"text": "Non-smoking rooms are available.",
"attributeValueCode": "NO SMOKING"
},
{
"text": "Property entirely non-smoking",
"attributeValueCode": "NONSMOKING"
},
{
"text": "Packages are available.",
"attributeValueCode": "PACKAGE"
},
{
"text": "Refrigerators in rooms.",
"attributeValueCode": "REFRIGERATORS"
},
{
"text": "Suites at property with active rates",
"attributeValueCode": "SUITES"
}
],
"resortSearchRate": {
"resortRatePlan": "RACK",
"resortRateCode": "RACK",
"totalAmount": 129,
"resortRoomCategory": "2290273"
},
"tripAdvisor": {
"resort": "19100",
"medianUserRating": 4.0,
"reviewCount": 90,
"tripAdvisorId": 578901
},
"resortRestriction": ""
}
]
解决方案
您必须将您的属性映射到 Schema.org 属性。
您的数据似乎与度假村有关,因此您可以使用该Resort
类型。此类型页面列出了Resort
Schema.org 中可以拥有的所有属性。
例如,您searchableAmenities
可以映射到 Schema.org's amenityFeature
,其中每个值都有 type LocationFeatureSpecification
。
对于无法映射的相关属性(因为 Schema.org 没有针对每种情况的属性),您可以使用additionalProperty
.
使用映射,有两种方法:
- 您可以使用自己的词汇表发布所有数据,并且仅在可以映射的地方使用 Schema.org 词汇表。
- 或者您只能使用 Schema.org 词汇表并忽略无法映射的数据。
推荐阅读
- xcode - 有没有一种部署方法可以将 alexa 技能转换为 Xcode 上的 IOS 应用程序?
- .net - 如何在使用区域的 razor 组件库中使用 blazor 服务器端?
- ibm-information-server - 在带有 Information Server 的服务器上安装 Discovery
- xamarin - 在共享项目中设置 AndroidResource 构建操作
- java - 使用 I/O 流解析 CSV 文件
- java - IntelliJ IDEA 中的 UnsupportedClassVersionError 故障排除
- tinymce - 图像未在 tinMCE 中显示
- java - 不兼容的类型不允许在 JOOQ dsl 中合并子查询
- ruby-on-rails - 在 erb 模板中创建实例变量
- java - 通过 apache-common-email 发送时如何保持 ssh 密钥文件的相同权限