GVKun编程网logo

语法错误:JSON.parse 位置 0 处的 JSON 中的意外标记 u(json.parse异常处理)

7

关于语法错误:JSON.parse位置0处的JSON中的意外标记u和json.parse异常处理的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Angular2SyntaxError:JS

关于语法错误:JSON.parse 位置 0 处的 JSON 中的意外标记 ujson.parse异常处理的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Angular 2 SyntaxError:JSON.parse()中位置0的JSON中的意外标记<、Arduino JSON over Serial,Json.Parse 返回意外的 JSON 输入、BASH:语法错误附近的意外标记`完成'别名为'做'、ESLINT:解析错误:package.json中的意外标记等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

语法错误:JSON.parse 位置 0 处的 JSON 中的意外标记 u(json.parse异常处理)

语法错误:JSON.parse 位置 0 处的 JSON 中的意外标记 u(json.parse异常处理)

由于您在没有第二个参数的情况下调用 useLocalStorage('id'),因此 initialValueundefined

if (jsonValue != null) return JSON.parse(jsonValue)
if (typeof initialValue === 'function') {
  return initialValue()
} else {
  return initialValue // this lines gets executed when `jsonValue` is null
}

最初,localStorage 不包含 whatsapp-clone-idjsonValuenull,这会导致上面的 else 块运行,将 value 设置为undefined。 (initialValueundefined

localStorage.setItem(prefixedKey,JSON.stringify(value))

useEffect 代码运行时,'undefined' 被设置在 whatsapp-clone-id 键中,因为 JSON.stringify(undefined)undefined。错误消息说它无法在运行 JSON.parse(jsonValue) 时解析 JSON,因为第一个字符(在位置 0)是 u 这不是有效的 JSON(第一个字符必须是 { ).

修复很简单。仅将值设置为 initialValue(如果存在)。否则,将其设置为 null{}

const jsonValue = localStorage.getItem(prefixedKey)
if (jsonValue != null) {
  return JSON.parse(jsonValue)
}
if (typeof initialValue === "function") {
  return initialValue()
}
if (initialValue) {
  return initialValue
}

return null

在尝试新代码之前,您必须运行 localStorage.removeItem('whatsapp-clone-id')

Angular 2 SyntaxError:JSON.parse()中位置0的JSON中的意外标记<

Angular 2 SyntaxError:JSON.parse()中位置0的JSON中的意外标记<

我从Visual Studio中的Angular2组件服务调用Web API,但我不断收到错误“ JSON.parse()中位置0的JSON中的意外标记<”. ComponentService:

import { Injectable } from '@angular/core';
       import {Http,Response } from '@angular/http';
       import { IData } from '../Common/details';
       import { Observable } from 'rxjs/Observable';
       import 'rxjs/add/operator/map';

       @Injectable()  
       export class AniversaryService {
         constructor(private _http:Http) { }
         getimages(): Observable<IData[]> {
                return this._http.get("/api/ImageService/Details")
                .map((response: Response) => <IData[]>response.json()      
                };
        }

和相应的组件是:

import { Component,OnInit } from '@angular/core';
    import { DomSanitizer } from '@angular/platform-browser';
    import { IData } from '../Common/details';
    import { AniversaryService } from './Aniversary.service';

    @Component({
    selector: 'my-AniversaryComponent',providers: [AniversaryService]
    })

    export class AniversaryComponent implements OnInit {
       data: IData[];
       constructor(private _aniversaryservice: AniversaryService) { }
       ngOnInit() {
       this._aniversaryservice.getimages().subscribe((details) => this.data 
       =details); 
       }
     }

    }

这些是网络标头和我的响应的图像(响应是在Javascript中):

In Developer tool the network Headers image:

and my response is in Javascript

有时我的状态代码显示200 ok和内容类型(在响应标题中):application / javascript

请帮我解决这个问题.

我在这里先向您的帮助表示感谢

解决方法

标题没用,数据也是如此.但错误信息很明确:您认为应该是JSON,以“<”开头作为第一个字符,JSON不会以“<”开头.很可能你收到的是html或xml.

Arduino JSON over Serial,Json.Parse 返回意外的 JSON 输入

Arduino JSON over Serial,Json.Parse 返回意外的 JSON 输入

我修好了,谢谢大家给我指明了正确的方向。问题出在我的 Arduino 代码中。我使用的是静态 JSON,它没有给我一个压缩字符串。

我将其切换为动态,如 https://arduinojson.org/ 文档中所述。

我的 Arduino 更改为以下内容。

#include <ArduinoJson.h>

void setup() {
  // put your setup code here,to run once:
  Serial.begin(9600);
}

void loop() {
  myFunction();
  delay(5000);
}

int myFunction(){
    DynamicJsonDocument doc(260);
    
    int temp = 21;
    int humidity = 99;
    
    doc["day"] = "Monday";
    doc["temperature"] = temp;
    doc["humidity"] = humidity;

    serializeJson(doc,Serial);
    Serial.println();
  }

BASH:语法错误附近的意外标记`完成'别名为'做'

BASH:语法错误附近的意外标记`完成'别名为'做'

这个问题似乎经常被问到,但对于我的问题仍然没有令人满意的答案。 因此,我希望你能帮助我。

在Ubuntu LTE 13.04下打开terminal时出现以下错误:

语法错误附近意外的令牌done'' bash: /usr/share/bash-completion/bash_completion: line 225: done''

我检查了具体的“bash_completion” – 似乎很好。 此外,我将其缩小到我的.bashrc文件中的以下命令。

bash用/在tetx文件中replace

Bash正则expression式匹配不起作用

如何在不修改FreeBSD,OpenBSD和Linux的情况下使用bash脚本?

复制unix中两个文件之间的差异

linux shell支持列表数据结构吗?

alias do=''rsync -r -e ssh --exclude=''file.py'' user@server.xxx.de:/path/to/folder /do/here''

虽然下面的工作完全没有任何exception:

alias up=''rsync -r -e ssh --exclude=''file.py'' /path/to/folder user@seerver.xxx.de:/do/here''

我检查了是否因为--exclude标志而发生,但是没有。 似乎命令有问题。 虽然两个命令都完美地完成了他们的工作 只有第一个提出错误。 有任何想法吗 ?

在GNU屏幕的hardstatus中显示一个窗口的用户

Linuxterminal:键入反馈消失了,换行符不显示

在bash中使用前面的命令的输出

Linux Bash脚本error handling

Shell脚本:从远程读取文件

在bash中, do是一个保留字。 它正在寻找一个do ... done块。 只要命名你的别名别的东西。

do是一个shell关键字。 您不能将其用作别名,而不会导致错误。

除此之外 – 考虑使用函数而不是别名; 他们提供了更多的控制。 这个别名可能被重写为:

do_sync() { rsync -r -e ssh --exclude=''file.py'' user@server.xxx.de:/path/to/folder /do/here "$@" }

使用函数而不是别名可以让你做条件逻辑,在尾部以外的位置插入参数,并且大大简化了引用(对于你的别名来说,这里的别名几乎肯定没有做你想做的事情,因为你使用的是在别名文本和别名文本中都是相同的引用类型,不能转义)。

总结

以上是小编为你收集整理的BASH:语法错误附近的意外标记`完成''别名为''做''全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

ESLINT:解析错误:package.json中的意外标记

ESLINT:解析错误:package.json中的意外标记

{
  "name": "react-redux-starter-kit","version": "1.0.0","description": "This would be the starter kit for react projects.","main": "index.html","scripts": {
    "start": "rm -rf build/ && rm -rf dist/ && webpack && webpack-dev-server --progress --colors","build": "rm -rf build/ && rm -rf dist/ && NODE_ENV=production webpack --config ./webpack.production.config.babel.js --progress"
  },"repository": {
    "type": "git","url": "git+https://rahulshettyprdxn@bitbucket.org/rahulshettyprdxn/react-devops.git"
  },"keywords": [
    "react","webpack","react-native"
  ],"author": "Rahul Shetty","license": "MIT","homepage": "https://bitbucket.org/rahulshettyprdxn/react-devops#readme","devDependencies": {
    "babel-core": "^6.5.2","babel-eslint": "^5.0.0","babel-loader": "^6.2.3","babel-plugin-react-transform": "^2.0.0","babel-preset-es2015-without-strict": "0.0.2","babel-preset-react": "^6.5.0","css-loader": "^0.23.1","eslint": "^2.2.0","eslint-plugin-react": "^4.1.0","extract-text-webpack-plugin": "^1.0.1","file-loader": "^0.8.5","html-webpack-plugin": "^2.9.0","image-webpack-loader": "^1.6.3","node-sass": "^3.4.2","react-css-modules": "^3.7.5","react-transform-hmr": "^1.0.2","sass-loader": "^3.1.2","style-loader": "^0.13.0","webpack": "^1.12.14","webpack-dev-server": "^1.14.1"
  },"dependencies": {
    "bootstrap": "^3.3.6","react": "^0.14.7","react-bootstrap": "^0.28.3","react-dom": "^0.14.7"
  }
}

以下是我收到的错误:
解析错误:Atom编辑器中第2行第8行的意外令牌.

请注意,我目前在Windows 10上收到此错误.

ESLint版本:
“eslint”:“^ 2.2.0”,
“eslint-plugin-react”:“^ 4.1.0”

我在我的Atom编辑器中安装了linter-eslint,并且关闭了Global npm ESLint设置.

我很困惑,因为错误消息不具有描述性.这绝不会妨碍我的项目,但我很好奇为什么我在编辑器中收到此错误.

解决方法

ESLint用于验证JavaScript,而不是JSON.

从the website开始:

ESLint

The pluggable linting utility for JavaScript and JSX

[强调我的]

(你可以在在线演示here上试试你的代码,你会得到同样的错误)

如果要在JSON文件上使用ESLint,可以使用像eslint-plugin-json这样的包.

关于语法错误:JSON.parse 位置 0 处的 JSON 中的意外标记 ujson.parse异常处理的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Angular 2 SyntaxError:JSON.parse()中位置0的JSON中的意外标记<、Arduino JSON over Serial,Json.Parse 返回意外的 JSON 输入、BASH:语法错误附近的意外标记`完成'别名为'做'、ESLINT:解析错误:package.json中的意外标记的相关信息,请在本站寻找。

本文标签: