如何为ContactPoint的每个contactType关联Person对象?
问题解决:为ContactPoint的每个contactType关联Person对象
错误原因
你原来的写法违反了JSON语法规范:数组contactType中混入了"Kundenservice": {...}这种对象键值对结构——数组元素必须是独立的JSON值(字符串、对象、数组等),不能直接写键值对,因此无法通过验证。
正确实现方案
方案1:遵循Schema.org规范(推荐)
Schema.org的ContactPoint类型提供了contactPerson属性用于关联联系人,同时保留contactType为文本类型。由于多个服务类型共享同一电话号码,可以创建多个ContactPoint实例,复用电话和区域信息:
"contactPoints": [ { "@type": "ContactPoint", "areaServed": "DE", "contactType": "Kundenservice", "telephone": "+1111111", "contactPerson": { "@type": "Person", "name": "John Q" } }, { "@type": "ContactPoint", "areaServed": "DE", "contactType": "Anfragen", "telephone": "+1111111" } ]
方案2:自定义合法JSON结构
如果需要在单个ContactPoint下关联多个类型与联系人,可以自定义一个数组字段(比如contactAssociations),每个元素包含contactType和对应的Person对象:
"contactPoint": { "@type": "ContactPoint", "areaServed": "DE", "telephone": "+1111111", "contactAssociations": [ { "contactType": "Kundenservice", "contactPerson": { "@type": "Person", "name": "John Q" } }, { "contactType": "Anfragen" } ] }
内容的提问来源于stack exchange,提问作者Evgeniy
相关产品推荐
相关产品推荐

