Skip to content

Commit

Permalink
Merge pull request origo-map#1707 from origo-map/fix-invalid-json
Browse files Browse the repository at this point in the history
fix: fix invalid backslash in json
  • Loading branch information
johnnyblasta committed Mar 6, 2023
2 parents e9164ff + 288fd34 commit 4252658
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/getfeatureinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,20 @@ function getFeatureInfoUrl({
if (res.error) {
return [];
}
return res.json();
return res.text();
})
.then(json => {
.then(text => {
let json = {};
try {
json = JSON.parse(text);
} catch (error) {
if (error instanceof SyntaxError) {
// Maybe bad escaped character, retry with escaping backslash
json = JSON.parse(text.replaceAll('\\', '\\\\'));
} else {
console.error(error);
}
}
if (json.features.length > 0) {
const copyJson = json;
copyJson.features.forEach((item, i) => {
Expand Down

0 comments on commit 4252658

Please sign in to comment.