从数组获取Json对象并将每个对象的键名放入Android

时间:2019-02-23 18:54:53

标签: arrays json

我正在使用这个图书馆com.github.vijayrawatsan:android-json-form-wizard:1.0

动态呈现inputForm。我的格式有些不同,需要按照Library Json格式进行转换。库需要以下json格式:

{
   "count":"3",
   "step1": {
      "fields": [
        {
            "key":"name",
            "type":"edit_text",
            "hint":"Enter Your Name",
            "value":"Vijay"
        },
        {
            "key":"email",
            "type":"edit_text",
            "hint":"Enter Your Email",
            "value":"dummy@gmail.com"
        },
        {
            "key":"labelBackgroundImage",
            "type":"label",
            "text":"Choose Background Image"
        },
        {
            "key":"chooseImage",
            "type":"choose_image",
            "uploadButtonText":"Choose",
            "value":"\/storage\/emulated\/0\/Pictures\/Wally\/10017.png"
        }
    ],
    "title":"Step 1 of 3",
    "next":"step2"
},
"step2":{
    "fields":[
        {
            "key":"name",
            "type":"edit_text",
            "hint":"Enter Country",
            "value":"India"
        },
        {
            "key":"checkData",
            "type":"check_box",
            "label":"Select multiple preferences",
            "options":[
                {
                    "key":"awesomeness",
                    "text":"Are you willing for some awesomeness?",
                    "value":"true"
                },
                {
                    "key":"newsletter",
                    "text":"Do you really want to opt out from my newsletter?",
                    "value":"false"
                }
            ]
        },
        {
            "key":"radioData",
            "type":"radio",
            "label":"Select one item from below",
            "options":[
                {
                    "key":"areYouPro",
                    "text":"Are you pro?"
                },
                {
                    "key":"areYouAmature",
                    "text":"Are you amature?"
                },
                {
                    "key":"areYouNovice",
                    "text":"Are you novice?"
                }
            ],
            "value":"areYouPro"
        }
    ],
    "title":"Step 2 of 3",
    "next":"step3"
},
"step3":{
    "fields":[
        {
            "key":"anything",
            "type":"edit_text",
            "hint":"Enter Anything You Want",
            "value":"anything"
        }
    ],
    "title":"Step 3 of 3"
}

}

但是我正在以这种格式从Server获取json数据,并且需要根据所需的库进行转换。

{

"count":3,
"steps":[
{

    "fields":[
              {
                "key":"customerFName",
                "type":"edit_text",
                "hint":"First Name",
                "v_min_length":{  "value" : "3",
                  "err" : "Min length should be at least 5"
                },
                "v_max_length":{  "value" : "20",
                  "err" : "Max length can be at most 20"
                }
              },

              {
                "key":"customerLName",
                "type":"edit_text",
                "hint":"Last Name",
                "v_min_length":{  "value" : "3",
                  "err" : "Min length should be at least 5"
                },
                "v_max_length":{  "value" : "20",
                  "err" : "Max length can be at most 20."
                }
              },

              {
                "key":"customerFatherName",
                "type":"edit_text",
                "hint":"Father Name",
                "v_min_length":{  "value" : "3",
                  "err" : "Min length should be at least 5"
                },
                "v_max_length":{  "value" : "20",
                  "err" : "Max length can be at most 20."
                }
              },

              {
                "key":"customerType",
                "type":"spinner",
                "hint": "Customer Type",
                "values":["Normal", "Individual"],
                "v_required":{  "value" : "true",
                  "err" : "Please choose a value to proceed."
                }
              },


              {
                "key":"title",
                "type":"spinner",
                "hint": "Customer Title",
                "values":["Mr", "Miss", "Mrs"],
                "v_required":{  "value" : "true",
                  "err" : "Please choose a value to proceed."
                }
              },

              {
                "key":"spouse",
                "type":"spinner",
                "hint": "Spouse",
                "values":["Husband", "Wife", "Gardian"],
                "v_required":{  "value" : "false",
                  "err" : "Please choose a value to proceed."
                }
              },

              {
                "key":"spouseName",
                "type":"edit_text",
                "hint":"spouse Name",
                "v_min_length":{  "value" : "3",
                  "err" : "Min length should be at least 5"
                },
                "v_max_length":{  "value" : "20",
                  "err" : "Max length can be at most 20."
                }
              }
          ],
          "duplicateStep":false
        },
        {

             "fields":[
              {
                 "key":"identificationType",
                 "type":"spinner",
                 "hint": "identification Type",
                 "values":["CNIC", "Old CNIC", "Token"],
                 "v_required":{  "value" : "true",
                 "err" : "Please choose a value to proceed."
             }
         },

         {
             "key":"identificationNumber",
             "type":"edit_text",
             "edit_type":"number",
             "hint":"Identification Number",
             "v_numeric":{  "value" : "true",
             "err" : "Invalid Identification Number"
               },
             "v_min_length":{  "value" : "13",
                    "err" : "Min length should be at least 13"
               },
             "v_max_length":{  "value" : "13",
                    "err" : "Max length can be at most 13."
              }
         },

         {
             "key":"dateOfIssue",
             "type":"calender",
             "hint":"Date of Issue",
             "v_date":{  "value" : "true",
             "err" : "Invalid Date"
              },
             "v_min_date":{  "value" : "2015-06-26",
             "date_format" : "yyyy-MM-dd"
              },
             "v_max_date":{  "value" : "2019-02-21",
             "date_format" : "yyyy-MM-dd"
              }
         },

         {
            "key":"dateOfExpiry",
            "type":"calender",
            "hint":"Date of Expiry",
            "v_date":{  "value" : "true",
                     "err" : "Invalid Date"
            },
            "v_min_date":{  "value" : "2010-07-12",
                    "date_format" : "yyyy-MM-dd"
            },
            "v_max_date":{  "value" : "2022-02-21",
                    "date_format" : "yyyy-MM-dd"
            }
        },

        {
            "key":"gender",
            "type":"spinner",
            "hint": "Gender",
            "values":["Male", "Female"],
            "v_required":{  "value" : "true",
                 "err" : "Please choose a value to proceed."
            }
        },

        {
            "key":"dateOfBirth",
            "type":"calender",
            "hint":"Date of Birth"
        },


        {
            "key":"occupation",
            "type":"edit_text",
            "hint":"Occupation",
            "v_min_length":{  "value" : "5",
                 "err" : "Min length should be at least 5"
            },
            "v_max_length":{  "value" : "50",
                 "err" : "Max length can be at most 50."
            }
        }
    ],
   "duplicateStep":false
},
{

    "fields":[
              {
    "key":"familySize",
    "type":"edit_text",
    "edit_type":"number",
    "hint":"Family Size",
    "v_numeric":{  "value" : "true",
      "err" : "Invalid Family Size"
    },
    "v_min_value":{  "value" : "2",
      "err" : "Min family size should be at least 2"
    },
    "v_max_value":{  "value" : "15",
      "err" : "Max family size can be at most 13."
    }
  },


  {
    "key":"education",
    "type":"spinner",
    "hint": "Education",
    "values":["Matric", "Under Matric", "Inter"],
    "v_required":{  "value" : "true",
      "err" : "Please choose a value to proceed."
    }
  },

  {
    "key":"maritalStatus",
    "type":"spinner",
    "hint": "Marital Status",
    "values":["Married", "Single"],
    "v_required":{  "value" : "true",
      "err" : "Please choose a value to proceed."
    }
  },

  {
    "key":"residentialStatus",
    "type":"spinner",
    "hint": "residential Status",
    "values":["Resident", "Non-Resident"],
    "v_required":{  "value" : "true",
      "err" : "Please choose a value to proceed."
    }
  },

  {
    "key":"customerClassification",
    "type":"spinner",
    "hint": "Customer Classification",
    "values":["Business group", "Individual"],
    "v_required":{  "value" : "true",
      "err" : "Please choose a value to proceed."
    }
  },

  {
    "key":"nature",
    "type":"spinner",
    "hint": "Nature",
    "values":["Normal", "Bad Client"],
    "v_required":{  "value" : "true",
      "err" : "Please choose a value to proceed."
    }
  },


  {
    "key":"adreessLine1",
    "type":"edit_text",
    "hint":"Adreess Line 1"

  },

  {
    "key":"adreessLine2",
    "type":"edit_text",
    "hint":"Adreess Line 2"

  }
  ],
  "duplicateStep":false
}

]

}

现在这里的问题是,我正在获取步骤数组,但是为了使用库,我想从步骤数组中拉出每个对象,并想使用键step1,step2,step3来制作每个单独的对象...

有人可以帮我吗... ??

0 个答案:

没有答案