jQuery键和它来自JSON数组的值

时间:2013-05-01 17:12:47

标签: javascript jquery json

我有一个很长的JSON数组,我希望从中删除一个特定的键及其值,然后将其重新构造为JSON数组。

如何从以下JSON数组中删除question_title,然后以相同的方式重新创建它?

[
{
  "question_title":"1110112x100012 (equal to)",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1140",
  "questions":[
     {
        "op_key":1,
        "op_val":"111101101"
     },
     {
        "op_key":2,
        "op_val":"111101100"
     },
     {
        "op_key":3,
        "op_val":"1111101011"
     },
     {
        "op_key":4,
        "op_val":"1100110"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"Information related to functioning of organization such as project plans is ________ information",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1142",
  "questions":[
     {
        "op_key":1,
        "op_val":"Internal use only"
     },
     {
        "op_key":2,
        "op_val":"Confidential"
     },
     {
        "op_key":3,
        "op_val":"Proprietary"
     },
     {
        "op_key":4,
        "op_val":"Business"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"Conceptual schema is a definition of the total database.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1147",
  "questions":[
     {
        "op_key":1,
        "op_val":"TRUE"
     },
     {
        "op_key":2,
        "op_val":"FALSE"
     },
     {
        "op_key":3,
        "op_val":""
     },
     {
        "op_key":4,
        "op_val":""
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"The schema for the external and internal levels is kept by the database in its System Tables.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1132",
  "questions":[
     {
        "op_key":1,
        "op_val":"TRUE"
     },
     {
        "op_key":2,
        "op_val":"FALSE"
     },
     {
        "op_key":3,
        "op_val":""
     },
     {
        "op_key":4,
        "op_val":""
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"What is the role of software in DBMS?",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1149",
  "questions":[
     {
        "op_key":1,
        "op_val":"Storing and managing the data"
     },
     {
        "op_key":2,
        "op_val":"Managing user"
     },
     {
        "op_key":3,
        "op_val":"Physically storing data"
     },
     {
        "op_key":4,
        "op_val":"All of the above"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"__________ databases are generally splitted by using a common delimiter.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1144",
  "questions":[
     {
        "op_key":1,
        "op_val":"Advanced"
     },
     {
        "op_key":2,
        "op_val":"Relational"
     },
     {
        "op_key":3,
        "op_val":"Structured"
     },
     {
        "op_key":4,
        "op_val":"Flat file"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
},
{
  "question_title":"Tally is a type of ERP.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1137",
  "questions":[
     {
        "op_key":1,
        "op_val":"TRUE"
     },
     {
        "op_key":2,
        "op_val":"FALSE"
     },
     {
        "op_key":3,
        "op_val":""
     },
     {
        "op_key":4,
        "op_val":""
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
},
{
  "question_title":"Data by itself is not useful unless",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1141",
  "questions":[
     {
        "op_key":1,
        "op_val":"It is massive"
     },
     {
        "op_key":2,
        "op_val":"It is processed to obtain information"
     },
     {
        "op_key":3,
        "op_val":"It is collected from diverse sources"
     },
     {
        "op_key":4,
        "op_val":"It is properly stated "
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"Pay slip and Bio-data are example of what kind of information?",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1145",
  "questions":[
     {
        "op_key":1,
        "op_val":"Business"
     },
     {
        "op_key":2,
        "op_val":"Personal"
     },
     {
        "op_key":3,
        "op_val":"General"
     },
     {
        "op_key":4,
        "op_val":"AtalpahdHelloB"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"The most commonly used system for representing signal binary numbers is the ________",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1150",
  "questions":[
     {
        "op_key":1,
        "op_val":"1?s complement system"
     },
     {
        "op_key":2,
        "op_val":"2?s complement system"
     },
     {
        "op_key":3,
        "op_val":"Complement system"
     },
     {
        "op_key":4,
        "op_val":"Sign magnitude "
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"CGI is ______",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1139",
  "questions":[
     {
        "op_key":1,
        "op_val":"Computer generated imaging"
     },
     {
        "op_key":2,
        "op_val":"Computer generated interface"
     },
     {
        "op_key":3,
        "op_val":"Computer graphical information"
     },
     {
        "op_key":4,
        "op_val":"Computer generated information"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"Database is a _________ of data structured in such a way that it may serve various applications.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1135",
  "questions":[
     {
        "op_key":1,
        "op_val":"System"
     },
     {
        "op_key":2,
        "op_val":"Folder"
     },
     {
        "op_key":3,
        "op_val":"Method"
     },
     {
        "op_key":4,
        "op_val":"File"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"A management information system is one which",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1134",
  "questions":[
     {
        "op_key":1,
        "op_val":"Is required by all managers of an organization"
     },
     {
        "op_key":2,
        "op_val":"Processes data to yield information of value in tactical management"
     },
     {
        "op_key":3,
        "op_val":"Provides operational information"
     },
     {
        "op_key":4,
        "op_val":"Allows better management of organizations"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"______ Technology, enabled internet access on mobile phones.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1138",
  "questions":[
     {
        "op_key":1,
        "op_val":"SAP"
     },
     {
        "op_key":2,
        "op_val":"WAP"
     },
     {
        "op_key":3,
        "op_val":"GSM"
     },
     {
        "op_key":4,
        "op_val":"PCS"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"There can be n number of primary keys in a table.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1131",
  "questions":[
     {
        "op_key":1,
        "op_val":"TRUE"
     },
     {
        "op_key":2,
        "op_val":"FALSE"
     },
     {
        "op_key":3,
        "op_val":""
     },
     {
        "op_key":4,
        "op_val":""
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"Database management systems are intended to?_____?",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1133",
  "questions":[
     {
        "op_key":1,
        "op_val":"Eliminate data redundancy"
     },
     {
        "op_key":2,
        "op_val":"Establish relationship among records in different files"
     },
     {
        "op_key":3,
        "op_val":"Manage file access"
     },
     {
        "op_key":4,
        "op_val":"All of the above"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"_________ software that automatically converts images into text.",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1148",
  "questions":[
     {
        "op_key":1,
        "op_val":"CGI"
     },
     {
        "op_key":2,
        "op_val":"Bluescreen"
     },
     {
        "op_key":3,
        "op_val":"OCR"
     },
     {
        "op_key":4,
        "op_val":"MICR "
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"Binary multiplication 1x0 (equals to)",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1143",
  "questions":[
     {
        "op_key":1,
        "op_val":"1"
     },
     {
        "op_key":2,
        "op_val":"0"
     },
     {
        "op_key":3,
        "op_val":"10"
     },
     {
        "op_key":4,
        "op_val":"11"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"Office automation systems that are capable of sharing information simultaneously, between more than one user, are termed as _______",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1136",
  "questions":[
     {
        "op_key":1,
        "op_val":"Cluster systems"
     },
     {
        "op_key":2,
        "op_val":"Meeting systems"
     },
     {
        "op_key":3,
        "op_val":"Multiple-user systems"
     },
     {
        "op_key":4,
        "op_val":"Groupware systems"
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 },
 {
  "question_title":"What is redundant data?",
  "new_attempt_id":"ATT-1187",
  "unique_question_code":"QUES-1146",
  "questions":[
     {
        "op_key":1,
        "op_val":"Private Data"
     },
     {
        "op_key":2,
        "op_val":"Duplicate Data"
     },
     {
        "op_key":3,
        "op_val":"Extra Data"
     },
     {
        "op_key":4,
        "op_val":"Meaningless Data "
     }
  ],
  "selected_answer":"",
  "selected_after_shuffle":"",
  "marked_for_review":"",
  "attempted":""
 }
]

我该如何解决?

1 个答案:

答案 0 :(得分:4)

假设您在名为json_content的字符串中有JSON:

var question_list = JSON.parse(json_content);

for(var i=0; i < question_list.length; ++i) {
    var question = question_list[i];
    delete question["question_title"];
}

var new_json_content = JSON.stringify(question_list);

一旦将数据解析为具有JSON.parse的对象,您就可以delete数组中每个对象的属性。然后,使用JSON.stringify生成新的JSON。

现代浏览器支持JSON对象;旧浏览器需要polyfill