Skip to content

Commit

Permalink
fix: json object parsing on feature properties #147
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Feb 21, 2024
1 parent ab7389e commit 5bb660f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions stores/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,26 @@ export const mapStore = defineStore('map', {
else {
const goodFeature = feature

const IsJsonString = (str: string) => {
function isJsonObject(item: string): boolean {
let value = false
try {
JSON.parse(str)
value = JSON.parse(item)
}
catch (e) {
return false
}
return true

return typeof value === 'object' && value !== null
}

if (feature?.properties) {
const cleanProperties: { [key: string]: any } = {}

Object.keys(feature.properties).forEach((key) => {
if (key !== 'stars' && IsJsonString(feature.properties[key]))
if (isJsonObject(feature.properties[key]))
cleanProperties[key] = JSON.parse(feature.properties[key])
else cleanProperties[key] = feature.properties[key]
})

goodFeature.properties = cleanProperties as ApiPoiProperties
}

Expand Down

0 comments on commit 5bb660f

Please sign in to comment.