提取API从响应中获取原始值

编程入门 行业动态 更新时间:2024-10-27 15:19:15
本文介绍了提取API从响应中获取原始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用React-Native请求一些数据,这是我的代码:

I use React-Native request some data, here is my code:

fetch('raw.githubusercontent/facebook/react-native/master/docs/MoviesExample.json') .then((response)=>{ return response.json() }) .then((responseJSON)=>{ callback(responseJSON) }) .catch((error)=>{ console.error(error); }) .done()

我看到response是Response对象,而json功能代码是return this.text().then(JSON.parse),我很困惑JSON.parse的参数是什么?那是response原始值吗?我怎么能得到它?

I see the response is a Response object, and the json function code is return this.text().then(JSON.parse), I'm confused that what is the parameter of theJSON.parse? Is that the response raw value? How can I get it?

推荐答案

以下是您要执行的操作.就我而言,我想手动解析JSON,因为内置JSON解析器不正确地解析了某个字符(\ u001e).

Here's how you'd do what you want. In my case I wanted to manually parse the JSON because a certain character (\u001e) is improperly parsed by the in-built JSON parser.

更改自:

fetch(url) .then(response => response.json()) .then((data) => { data....

收件人:

fetch(url) .then(response => response.text()) .then((dataStr) => { let data = JSON.parse(dataStr); data...

更多推荐

提取API从响应中获取原始值

本文发布于:2023-11-25 13:40:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629974.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原始   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!