Javascript ng重复json解析显示空字符串

Javascript ng重复json解析显示空字符串,javascript,angularjs,json,pug,Javascript,Angularjs,Json,Pug,我从数组列表中获取了对象数组字符串。我使用JSON.parse方法将对象字符串转换为对象,但它在ng repeat中显示为空 翡翠 .item.col-md-4(ng-repeat='p in searchData | filter: paginate | orderBy: sortKey ') // `p` is a object of string, for example "{id:2, name:'abel'}"; - var property = JSO

我从数组列表中获取了对象数组字符串。我使用
JSON.parse方法将对象字符串转换为对象,但它在ng repeat中显示为空

翡翠

.item.col-md-4(ng-repeat='p in searchData | filter: paginate | orderBy: sortKey ')
   // `p` is a object of string, for example "{id:2, name:'abel'}";
   - var property = JSON.parse("{{ p }}"); // Error at this line
   +AddPropertyCard(property)
搜索数据

[{id:0, name:"abel"},{id:1, name:"julia"}]
错误

var property=JSON.parse(“”)

JSON中位置1处的意外标记{


更新1

变量“p”似乎是对象

您必须使用点符号访问它。 类似于{p.id}{{p.name}。这将显示相应的值


JSON.parse需要对象字符串来解析它。

// Lets create a simple Object in javascript
var notStringObj = {
    "name": "John",
    "age": 30,
    "city": "New York"
};
console.log("JavaScript Object", notStringObj);

// Lets stringify (Convert in string) the object
var stringObj = JSON.stringify(notStringObj);
console.log("JavaScript Stringified Object", stringObj);

// Following is code to decode this object

// This will give you result you are expecting i.e. JavaScript Object
var obj1 = JSON.parse(stringObj);

// This will throw error - Unexpected token { in JSON at position 1
// Because this was plain object not a string
// JSON.parse expects object string in order to Parse it
var obj2 = JSON.parse(notStringObj)

更新1

变量“p”似乎是对象

您必须使用点符号访问它。 类似于{p.id}{{p.name}。这将显示相应的值


JSON.parse需要对象字符串来解析它。

// Lets create a simple Object in javascript
var notStringObj = {
    "name": "John",
    "age": 30,
    "city": "New York"
};
console.log("JavaScript Object", notStringObj);

// Lets stringify (Convert in string) the object
var stringObj = JSON.stringify(notStringObj);
console.log("JavaScript Stringified Object", stringObj);

// Following is code to decode this object

// This will give you result you are expecting i.e. JavaScript Object
var obj1 = JSON.parse(stringObj);

// This will throw error - Unexpected token { in JSON at position 1
// Because this was plain object not a string
// JSON.parse expects object string in order to Parse it
var obj2 = JSON.parse(notStringObj)

你能给我们看一下你的JSON吗?看来
p
是空的,先检查chehck
p
的值。@leaf the{{p}返回object。这不起作用,jade正在尝试解析服务器上的属性,而不是客户端,但是ng repeat没有在服务器上展开。除此之外,您不需要
JSON。这里无论如何解析
;ng repeat应该已经有单个
p
对象、
{p.id}
{p.name}
应该直接输出。更可能的是,您只需要
+AddPropertyCard(p)
,带有
JSON.parse
的行就可以完全消失。您能给我们看一下您的JSON吗?看来
p
是空的,请先选中
p
的值。@leaf the{{p}返回object。这不起作用,jade正在尝试解析服务器上的属性,而不是客户端,但是ng repeat没有在服务器上展开。除此之外,您不需要
JSON。这里无论如何解析
;ng repeat应该已经有单个
p
对象、
{p.id}
{p.name}
应该直接输出。更可能的是,您只需要
+AddPropertyCard(p)
,带有
JSON.parse
的行可以完全消失。它不再显示错误。使用JSON.stringify,它显示为空。p变量具有来自ng repeat的对象。但是显示nothing@AbelChun'p'是一个对象。您必须使用点表示法访问它。请尝试像{{p.id}}、{{p.name}这样访问。它不会显示任何错误,然后不再显示错误。对于JSON.stringify,它显示为空。p变量具有来自ng repeat的对象。但显示nothing@AbelChun'p'是一个对象。您必须使用点表示法访问它。请尝试像{p.id}、{{p.name}这样访问。然后它不会显示任何错误