Parsing error: Missing '}' or object member name
Parsing error: Missing '}' or object member name
使用 google 网络控制台验证我的网站 json-ld 标签时,发出以下解析错误:
Parsing error: Missing '}' or object member name
这是我的代码,因为当我尝试修复它时 google 从每天 1 万次展示下降到 400 次展示
<script type="application/ld+json">
/* START TEST */
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
/* "description" : "<p>{{ \Illuminate\Support\Str::limit($post->description, 270) }}</p>", */
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
/*"validThrough" : "2021-08-18T00:00",*/
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
@if (isset($post->company) and !empty($post->company))
<?php $attr = ['countryCode' => config('country.icode'), 'id' => $post->company->id]; ?>
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@else
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@endif
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
@if ($post->salary_min > 0 or $post->salary_max > 0)
@if ($post->salary_min > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@else if ($post->salary_max > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@endif
@endif
以前当我忽略那个错误时它起作用了。
如果您只查看 JSON 并删除所有 PHP 并通过 JSON 验证器对其进行解析,您将意识到错误是您没有关闭 JSON块。
如果您删除 PHP 并将 "value": {{$post->salary_max}},
替换为 "value": "{{$post->salary_max}}",
,这样 JSON 验证器就可以吃掉它。
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": "{{$post->salary_max}}",
"unitText": "{{ $post->salaryType->name }}"
}
}
您将收到预期 }
或 ,
的错误,但收到 EOF。
原因是您缺少第一个 {
.
的结尾 }
最后的 JSON 应该是这样的:
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": "{{$post->salary_max}}",
"unitText": "{{ $post->salaryType->name }}"
}
}
}
因此您的代码应更改为包括:
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
/* "description" : "<p>{{ \Illuminate\Support\Str::limit($post->description, 270) }}</p>", */
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
/*"validThrough" : "2021-08-18T00:00",*/
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
@if (isset($post->company) and !empty($post->company))
<?php $attr = ['countryCode' => config('country.icode'), 'id' => $post->company->id]; ?>
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@else
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@endif
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
@if ($post->salary_min > 0 or $post->salary_max > 0)
@if ($post->salary_min > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@else if ($post->salary_max > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@endif
@endif
}
使用 google 网络控制台验证我的网站 json-ld 标签时,发出以下解析错误:
Parsing error: Missing '}' or object member name
这是我的代码,因为当我尝试修复它时 google 从每天 1 万次展示下降到 400 次展示
<script type="application/ld+json">
/* START TEST */
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
/* "description" : "<p>{{ \Illuminate\Support\Str::limit($post->description, 270) }}</p>", */
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
/*"validThrough" : "2021-08-18T00:00",*/
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
@if (isset($post->company) and !empty($post->company))
<?php $attr = ['countryCode' => config('country.icode'), 'id' => $post->company->id]; ?>
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@else
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@endif
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
@if ($post->salary_min > 0 or $post->salary_max > 0)
@if ($post->salary_min > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@else if ($post->salary_max > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@endif
@endif
以前当我忽略那个错误时它起作用了。
如果您只查看 JSON 并删除所有 PHP 并通过 JSON 验证器对其进行解析,您将意识到错误是您没有关闭 JSON块。
如果您删除 PHP 并将 "value": {{$post->salary_max}},
替换为 "value": "{{$post->salary_max}}",
,这样 JSON 验证器就可以吃掉它。
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": "{{$post->salary_max}}",
"unitText": "{{ $post->salaryType->name }}"
}
}
您将收到预期 }
或 ,
的错误,但收到 EOF。
原因是您缺少第一个 {
.
的结尾 }
最后的 JSON 应该是这样的:
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": "{{$post->salary_max}}",
"unitText": "{{ $post->salaryType->name }}"
}
}
}
因此您的代码应更改为包括:
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "{{ $post->title }}",
"description" : "{{ $post->description }}",
/* "description" : "<p>{{ \Illuminate\Support\Str::limit($post->description, 270) }}</p>", */
"identifier": {
"@type": "PropertyValue",
"name": "{{ $post->company_name }}",
"value": "{{ $post->id }}"
},
"datePosted" : "{{ $post->created_at }}",
/*"validThrough" : "2021-08-18T00:00",*/
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "{{ $post->company_name }}",
"sameAs" : "{{ $post->company_website }}",
@if (isset($post->company) and !empty($post->company))
<?php $attr = ['countryCode' => config('country.icode'), 'id' => $post->company->id]; ?>
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@else
"logo" : "{{ imgUrl($post->logo, 'medium') }}"
@endif
},
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "{{ $post->city->name }}"
}
},
@if ($post->salary_min > 0 or $post->salary_max > 0)
@if ($post->salary_min > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@else if ($post->salary_max > 0)
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": {{$post->salary_max}},
@if (!empty($post->salaryType))
"unitText": "{{ $post->salaryType->name }}"
@else {
"unitText": "MONTH"
}
@endif
}
}
@endif
@endif
}