【发布时间】:2015-03-22 21:49:45
【问题描述】:
您好,我想知道如何尝试解析从数据库中检索到的数据:
[
{
"q_id":"1",
"type":"for",
"author":"kappa420",
"question":"what is the meaning of life?",
"answer":"good question."
},
{
"q_id":"2",
"type":"recursive",
"author":"kappa420",
"question":"If only you knew",
"answer":"That I was right behind you!"
},
{
"q_id":"3",
"type":"while",
"author":"kappa420",
"question":"who are you?",
"answer":"ha-HA!"
},
{
"q_id":"5",
"type":"testtyte",
"author":"testauthor",
"question":"testquestion",
"answer":""
},
{
"q_id":"6",
"type":"testtyte",
"author":"testauthor",
"question":"testquestion",
"answer":"testanswer"
},
{
"q_id":"7",
"type":"public int add( int num1,",
"author":"",
"question":"Given two numbers the user must be able to add these numbers. ",
"answer":" add(5,4) = 9\r\n add(2,3) = 5"
},
{
"q_id":"8",
"type":"public int add( int num1,",
"author":"",
"question":"Given two numbers the user must be able to add these numbers. ",
"answer":" add(5,4) = 9\r\n add(2,3) = 5"
},
{
"q_id":"9",
"type":"dasdsa",
"author":"",
"question":" adddfa",
"answer":" asdfs"
},
{
"q_id":"10",
"type":"adfafd",
"author":"",
"question":" dsadsf",
"answer":" saddasf"
},
{
"q_id":"11",
"type":"adsf",
"author":"",
"question":" adsfs",
"answer":" dsadsf"
}
]
有没有办法获取某些元素,如 q_id 和 author 并将它们放入 html 属性中?
【问题讨论】:
-
您能否解释一下这些数据是如何提供给页面的(作为 JSON 或 JavaScript 对象,也可能通过 AJAX)?
-
II 到来自服务器的 curl 请求并且服务器响应,然后我使用 PHP 和 jQuery 将其打印出来。