【发布时间】:2018-01-09 08:41:00
【问题描述】:
我收到了这个复杂的 JSON 数据,需要帮助将其转换为 hashmap 以存储到 couchbaselite 文档数据库中。然后将使用 Couchbase lite 查询来查询其他功能。我使用改造接收 JSON 数据,并设计了模型类来处理从 API 接收的数据。
{
'project_id': 'PROJ10001',
'project_name':'Sample Project',
'forms': [
{
'form_name': 'main',
'form_id': 'FORM001',
'variables': [
{
'id':'VAR0001',
'variable_name': 'firstname',
'variable_label': 'First Name',
'input_type': 'text',
'hidden_text': '',
'required': '1',
'options': {},
'default_value': 'n/a',
'max_length': 50,
'min_length': 2
'pre_condition': '',
'post_condition': '',
'order_in_form': '1'
},
{
'id':'VAR0002',
'variable_name': 'age',
'variable_label': 'What is your current age',
'input_type': 'number',
'hidden_text': '',
'required': '1',
'options': {},
'default_value': '0',
'max_length': 3,
'min_length': 2
'pre_condition': '',
'post_condition': '',
'order_in_form': '2'
},
{
'id':'VAR0003',
'variable_name': 'gender',
'variable_label': 'Gender',
'input_type': 'options',
'hidden_text': '',
'required': '1',
'options': {
'type':'list',
'multi':'0',
items:[
{'label':'Male','value:'m', skip:''},
{'label':'Female','value':f', skip:''}
]
},
'default_value': '0',
'max_length': 3,
'min_length': 2
'pre_condition': '',
'post_condition': '',
'order_in_form': '3'
}]
},
{
'form_name': 'male_form',
'form_id': 'FORM002',
'variables': [
{
'id':'VAR0004',
'variable_name': 'beard',
'variable_label': 'How many shirts do you have?',
'input_type': 'number',
'hidden_text': '',
'required': '1',
'options': {},
'default_value': 'n/a',
'max_length': 3,
'min_length': 2
'pre_condition': '',
'post_condition': '',
'order_in_form': '1'
}]
}]
}
【问题讨论】:
-
您在尝试转换时遇到了什么问题?
-
我是手动做的,我想要一个快速的方法,通过循环或其他方法