简体   繁体   English

jQuery键及其来自JSON数组的值

[英]jQuery key and it's value from a JSON array

I have a long JSON array from which I would like to remove a specific key and its value and then re-construct it as a JSON array. 我有一个长的JSON数组,我想从中删除特定的键及其值,然后将其重新构造为JSON数组。

How do I remove question_title from the following JSON array and then recreate it the same way? 如何从以下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":""
 }
]

How do I go about it? 我该怎么办?

Assuming you have the JSON in a string called json_content : 假设您在名为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);

You can delete the property from each object in the array once you parse it into an object with JSON.parse . 一旦使用JSON.parse将其解析为对象,就可以从数组中的每个对象delete该属性。 Then, use JSON.stringify to produce new JSON. 然后,使用JSON.stringify生成新的JSON。

The JSON object is supported in modern browsers; 现代浏览器支持JSON对象。 older browsers require a polyfill . 较旧的浏览器需要使用polyfill

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM