0
I’m trying to file a requisition HTTP
for a API
and I get the following error
:
Uncaught (in Promise) Syntaxerror: Unexpected token < in JSON at position 0
- Why is this happening
error
? - How to treat
XML
in the components ofReact
?
Call to API
:
plotarCamadaNoMapa(camadas) {
fetch('api/TelaOperadorRJ/GetXMLCamada?idCamada=' + camadas)
.then(response => response.json())
.then(data => {
this.setState({
xmlCamada: data
});
});
console.log(this.state.xmlCamada);
}
Filing cabinet XML
:
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="Style1">
<LineStyle>
<color>ff000000</color>
<width>1.2</width>
</LineStyle>
<PolyStyle>
<color>8000ffff</color>
<fill>true</fill>
<outline>true</outline>
</PolyStyle>
</Style>
<Placemark>
<name>Polígono 0</name>
<styleUrl>#Style1</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-46.878889999999998,-23.54439
-46.843359999999997,-23.52
-46.837859999999999,-23.516220000000001
-46.812629999999999,-23.522829999999999
-46.808340000000001,-23.54007
-46.797870000000003,-23.563590000000001
-46.814169999999997,-23.57067
-46.850740000000002,-23.56831
-46.878889999999998,-23.54439</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
Dear Igor just remove the
.then(response => response.json())
, XML is not JSON, so there’s no way he can interpret this– Guilherme Nascimento
It even worked, but went into an infinite looping.
– Igor Carreiro
Probably wrong somewhere else dear Igor
– Guilherme Nascimento