这是我要尝试在jobStatus对象内获取jobStatus的输出。它让我无法解析json对象
var x =
{ "jobStatus":
{ "jobStatus" : "COMPLETED"
, "jobType" : "xyz"
, "scheduleType": "Immediate"
, "startTime" : "Oct 10, 2019 2:20:45 AM"
, "endTime" : "Oct 10, 2019 2:20:48 AM"
, "Time" : "Oct 10, 2019 2:20:40 AM"
, "phase" : "null"
, "submittedBy" : "random"
}
}
我正在使用的代码
错误:
[$ http:baddata]数据必须是有效的JSON对象。收到:“完成”。解析错误: ”{}” https://errors.angularjs.org/1.7.8/ $ http / baddata?p0 = COMPLETED&p1 =%7B%7D```
var y = JSON.parse(x);
var status = y.jobStatus;
var y = JSON.parse(status);
var z = y.jobStatus;
Console.log(z)
答案 0 :(得分:0)
您无需解析任何内容的JSON或javascript对象
var x =
{ "jobStatus":
{ "jobStatus" : "COMPLETED"
, "jobType" : "xyz"
, "scheduleType": "Immediate"
, "startTime" : "Oct 10, 2019 2:20:45 AM"
, "endTime" : "Oct 10, 2019 2:20:48 AM"
, "Time" : "Oct 10, 2019 2:20:40 AM"
, "phase" : "null"
, "submittedBy" : "random"
}
}
let y = x.jobStatus.scheduleType
console.log( y )
// or
let z = x['jobStatus']['jobType']
console.log( z )
/* ------- */
var A =
{ jobStatus:
{ jobStatus : "COMPLETED"
, jobType : "xyz"
, scheduleType: "Immediate"
, startTime : "Oct 10, 2019 2:20:45 AM"
, endTime : "Oct 10, 2019 2:20:48 AM"
, Time : "Oct 10, 2019 2:20:40 AM"
, phase : "null"
, submittedBy : "random"
}
}
let B = A.jobStatus.jobType
console.log( B )
// or
let C = A['jobStatus']['scheduleType']
console.log( C )