我需要创建一个对象,它保存像[[{IMEI = 49015420323751}],[{PIN = 538000001}]]这样的值,以便将其转换为JSON.
现在我正在做的是
ArrayList<ArrayList<HashMap<String,String>>> Request_Identifiers = new ArrayList<ArrayList<HashMap<String,String>>>();
ArrayList<HashMap<String,String>> list1 = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map1 = new HashMap<String,String>();
map1.put("IMEI","49015420323751");
list1.add(map1);
ArrayList<HashMap<String,String>> list2 = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map2 = new HashMap<String,String>();
map2.put("PIN","538000001");
list2.add(map2);
Request_Identifiers.add(list1);
Request_Identifiers.add(list2);
Run Code Online (Sandbox Code Playgroud)
但我现在需要在构造函数中执行此操作(就像我可以初始化字符串数组new String [] {"blocked","suspended","classmask"})或为此编写setter方法.怎么做 ?我真的很困惑.如果有人可以帮助我,我会很高兴.
提前致谢.
编辑:
我需要在java中创建一个JSON对象,以便在java中传递请求
{
"attributes": ["blocked", "suspended"],
"authPolicy": ["device_valid"],
"identity": "first_id",
"encoding": "default",
"identifiers":
[
[
{"PIN": "234576"},
{"IMEI": "49015420323751"}
],
[
{"PIN": "68000001"}
]
]
}
Run Code Online (Sandbox Code Playgroud)
所以我正在编写一个java类,并计划使用gson转换为json格式
class RequestBody
{
String[] Request_Attributes;
String[] Request_Policies;
String Request_Identity;
String …Run Code Online (Sandbox Code Playgroud) 我正在关注http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out--net-29982教程来开发我自己的应用程序.
我试图创建一个注册表但遇到此错误:
TypeError: 'Required' object is not iterable
Run Code Online (Sandbox Code Playgroud)
我的路线页是
from cafe_klatch import app
from flask import render_template,request,flash
from forms import ContactForm, SignupForm
from models import db
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/contact', methods = ['GET','POST'])
def contact():
form1 = ContactForm()
if request.method == 'POST':
if form.validate() == False:
flash('All fields are required.')
return render_template('contact.html',form = form)
else:
return 'Form posted.'
elif request.method == 'GET':
return render_template('contact.html',form = form)
@app.route('/signup', methods =['GET','POST'])
def signup():
form = SignupForm()
if …Run Code Online (Sandbox Code Playgroud)