[英]Can't do JSON.parse on data from SQL Server
我有一個從SQL Server獲取數據的查詢,在一個字段中,我們將JSON存儲為varchar(max)
。 問題是,當我嘗試在Node應用程序中獲取數據並執行JSON.parse
,它不起作用。 這是我嘗試過的:
console.log(data.attr);
// "{ firstName: 'Preston', lastName: 'Lamb' }"
JSON.parse(data.attr)
// Invalid expression: unexpected end of input (get this on one item)
// invalid expression: unexpected token f in json at position 2 (and this on the other)
newJsonStr = JSON.stringify(data.attr)
// ""{ firstName: 'Preston', lastName: 'Lamb' }""
newJson = JSON.parse(newJsonStr)
// "{ firstName: 'Preston', lastName: 'Lamb' }"
這些都不是真正復雜的東西……JSON.parse和/或JSON.stringify應該很容易,但是它不起作用。 有什么想法嗎?
另一個注釋器不是JSON的意思是,您的密鑰需要用引號引起來以解析為JSON。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.