简体   繁体   English

错误:语法错误:React Native中位置0处JSON中的意外令牌i

[英]Error : SyntaxError: Unexpected token i in JSON at position 0 in React Native

react native fetching rejected with Error : SyntaxError: Unexpected token i in JSON at position 0 when applying the moment-timezone module 当应用moment-timezone模块时,对本机访存做出反应,拒绝,并出现错误:SyntaxError:JSON中位置0处的意外令牌i

i have used MomentTimezone.tz(new Date().getTime(), 'America/New_York') as the fetching request message value 我已经使用MomentTimezone.tz(new Date().getTime(), 'America/New_York')作为获取请求消息的值

You need to load timezone data first, before you parse timezone. 在解析时区之前,您需要先加载时区数据。 See the documentation at Moment Timezone Data Loading 请参阅时刻时区数据加载中的文档

Also I think you want to send date instead of New York Time. 另外,我认为您想发送日期而不是纽约时间。 Does your request actually requires That time can be used for display however if you have to send that time with your request (to a server) you need to convert your moment instance to date object like this 您的请求实际上是否需要该时间可以用于显示,但是如果您必须将时间与您的请求一起发送(到服务器),则需要像这样将您的moment实例转换为date对象

 const now = new Date(); const myMoment = momentTimezone.tz(now.getTime(), 'America/NewYork'); const dateForRequest = myMoment.toDate(); 

if you want new york time, you need to specify which time do you actually want. 如果您想要纽约时间,则需要指定您实际想要的时间。 Consider I want to know what will be the time( with respect to UTC or Epoch) when New York time will be 2017-12-1 03:30 . 考虑一下我想知道纽约时间是2017-12-1 03:30的时间(相对于UTC或Epoch)。

const timeString = '2017-12-1 03:30'
const myMoment = momentTimezone.tz(timeString, 'YYYY-MM-DD HH:mm', 'America/NewYork');
const dateForRequest = myMoment.toDate();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取错误:-S SyntaxError: Unexpected token &lt; in JSON at position 0 REACT - Fetch Error :-S SyntaxError: Unexpected token < in JSON at position 0 REACT 反应错误 - Uncaught SyntaxError: Unexpected token o in JSON at position 1 - react error - Uncaught SyntaxError: Unexpected token o in JSON at position 1 “SyntaxError: Unexpected token &lt; in JSON at position 0”在反应 js - "SyntaxError: Unexpected token < in JSON at position 0" in react js 我如何解决此错误“语法错误:JSON中位置0上的意外令牌&lt;” - How do i resolve this error “ SyntaxError: Unexpected token < in JSON at position 0” “SyntaxError:位于0的JSON中的意外标记u”错误 - “SyntaxError: Unexpected token u in JSON at position 0” Error 错误语法错误:JSON中位置0上的意外令牌&lt; - ERROR SyntaxError: Unexpected token < in JSON at position 0 错误消息:SyntaxError: Unexpected token &lt; in JSON at position 0 - Error message : SyntaxError: Unexpected token < in JSON at position 0 服务器语法错误错误:position 1 中的 JSON 中的意外令牌 < - Error with Server SyntaxError: Unexpected token < in JSON at position 1 错误:语法错误:意外的标记{位于JSON中的位置4 - Error : SyntaxError: Unexpected token { in JSON at position 4 SyntaxError: Unexpected token &lt; in JSON at position 0&quot; 错误在 AJAX - SyntaxError: Unexpected token < in JSON at position 0” error in AJAX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM