角度6:SyntaxError:JSON中的意外令牌O在JSON.parse位置0处具有有效JSON

我不确定我的功能是否错误,应该将数据发送到服务器,还是服务器上的功能错误。 我查找了类似的问题,但对问题采用的解决方案无效。

我的功能如下:

postData(number){
   let array = JSON.stringify(this.locArr);
   return this.http.post<any>(this.url,array)
    .subscribe(),error => console.log("Error: ",error)
    }

发送的JSON:

[ 
  { 
      "id":222,"name":"Lars","sLA":37
   },{ 
      "id":223,"name":"Sim","sLA":12
   }
]

服务器功能会接收令牌等所有参数,但我上面编写的数组为空,尽管它是有效的json。 我不知道为什么会发生此错误。

任何建议都值得赞赏

wazwsx 回答:角度6:SyntaxError:JSON中的意外令牌O在JSON.parse位置0处具有有效JSON

Angular会自动将本地数组转换为JSON,您无需对其进行字符串化或解析。

doit() {
    f="$1"
    line="$2"
    found=$(grep $line $f)      

    if [ ! -z "$found" ]; then
      perform task here
    fi
}
export -f doit

find . -type f | parallel doit :::: - data_file
,

我相信您正在使用httpClientModule,因此无需let quoteText = "Life is 10% what happens to you and 90% how you react to it." let activityViewController = UIActivityViewController(activityItems: [quoteText],applicationActivities: nil) if let popoverController = activityViewController.popoverPresentationController { popoverController.sourceRect = CGRect(x: UIScreen.main.bounds.width / 2,y: UIScreen.main.bounds.height / 2,width: 0,height: 0) popoverController.sourceView = self.view popoverController.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0) } UIApplication.topViewController?.present(activityViewController,animated: true,completion: nil) 删除此步骤JSON.stringify
另外,您还需要将其作为json对象JSON.stringify(this.locArr);而不是json数组{}

发送
[]
本文链接:https://www.f2er.com/3097138.html

大家都在问