在Java中循环使用JSON中的逻辑

时间:2016-10-10 06:13:38

标签: java json

我有一个JSON数组。 JSON如下所述。每个JSON元素都有一个字段类型。我需要的是,如果当前字段类型是描述性的,我必须获取nexts数组元素,直到遇到下一个描述性字段类型。

{  
      "field_name":"form_name_1",
      "form_name":"patient_details",
      "section_header":"",
      "field_type":"descriptive",
      "field_label":"<font size=3><i><b>Informed Consent<\/b><\/i><\/font>",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"",
      "text_validation_min":"",
      "text_validation_max":"",
      "identifier":"",
      "branching_logic":"",
      "required_field":"",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"vst_1_scrn_date",
      "form_name":"patient_details",
      "section_header":"",
      "field_type":"text",
      "field_label":"Visit 1 (Screening) Date:",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"date_dmy",
      "text_validation_min":"",
      "text_validation_max":"",
      "identifier":"",
      "branching_logic":"",
      "required_field":"y",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"consent_yes_no",
      "form_name":"patient_details",
      "section_header":"",
      "field_type":"yesno",
      "field_label":"Has the subject given written informed consent?",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"",
      "text_validation_min":"",
      "text_validation_max":"",
      "identifier":"",
      "branching_logic":"",
      "required_field":"y",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"patient_site_num",
      "form_name":"patient_details",
      "section_header":"",
      "field_type":"text",
      "field_label":"Patient site number:",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"number",
      "text_validation_min":"",
      "text_validation_max":"",
      "identifier":"",
      "branching_logic":"",
      "required_field":"y",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"patient_letter_code",
      "form_name":"patient_details",
      "section_header":"",
      "field_type":"text",
      "field_label":"Patient letter code:",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"",
      "text_validation_min":"",
      "text_validation_max":"",
      "identifier":"",
      "branching_logic":"",
      "required_field":"y",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"site_num",
      "form_name":"patient_details",
      "section_header":"",
      "field_type":"text",
      "field_label":"Site Number:",
      "select_choices_or_calculations":"",
      "field_note":"Belfast=01, Birmingham=02, Edinburgh=03, Imperial=04, Leicester=05, Manchester=06, Nottingham=07, Southhampton=08",
      "text_validation_type_or_show_slider_number":"number",
      "text_validation_min":"1",
      "text_validation_max":"10",
      "identifier":"",
      "branching_logic":"",
      "required_field":"y",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"early_cohort_num",
      "form_name":"patient_details",
      "section_header":"",
      "field_type":"text",
      "field_label":"Early cohort number:",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"number",
      "text_validation_min":"1000001",
      "text_validation_max":"10009999",
      "identifier":"",
      "branching_logic":"",
      "required_field":"y",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"form_name_2",
      "form_name":"visit_1_screening",
      "section_header":"",
      "field_type":"descriptive",
      "field_label":"<font size=3><i><b><u>Demographics<i><\/b><\/u><\/font>",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"",
      "text_validation_min":"",
      "text_validation_max":"",
      "identifier":"",
      "branching_logic":"",
      "required_field":"",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   },
   {  
      "field_name":"dob",
      "form_name":"visit_1_screening",
      "section_header":"",
      "field_type":"text",
      "field_label":"Date of Birth:",
      "select_choices_or_calculations":"",
      "field_note":"",
      "text_validation_type_or_show_slider_number":"date_dmy",
      "text_validation_min":"",
      "text_validation_max":"",
      "identifier":"",
      "branching_logic":"",
      "required_field":"y",
      "custom_alignment":"",
      "question_number":"",
      "matrix_group_name":"",
      "matrix_ranking":"",
      "field_annotation":""
   }

1 个答案:

答案 0 :(得分:1)

下面的代码将为您提供一个包含JSON数组的HashSet,其中包含每个部分的对象。

public void program()
{
    int sizeX = BuildingProperties.House.sizeX;
}

希望这就是你要找的东西