JSONArray jsonArray解析

try {
JSONArray jsonArray = new JSONObject(serviceMessage).getJSONArray("candidateList");
for(int i=0; i<jsonArray.length(); i++){

JSONObject jsonObject = (JSONObject)jsonArray.opt(i);

ResultEntity re = new ResultEntity();
int nMainIndex = jsonObject.getInt("MainIndex");
String imgPath = jsonObject.getString("ImgPath");
print("fingerImgPath=>"+imgPath);
re.setFacePath(imgPath);
//"Info":"Name:xxx,Sex:男,Nation:汉族",
String info = jsonObject.getString("Info");
String[] popArr = info.split(",");
re.setName(popArr[0].split(":")[1]);
re.setSex(popArr[1].split(":")[1]);
int score = Integer.parseInt(jsonObject.getString("score"));
score = score > 1000 ? 1000:score;
re.setscore(String.valueOf(score));
re.setTime(UtilHelper.getNowTimestr());
re.setMatchTpye("xxx");
re.setdbname(mdb.getName());
rst.add(re);
}
} catch (JSONException e) {

e.printstacktrace();

}



//保存一副图片函数

int MAXIMGSIZE = 655360;

int SaveRawToBmp(byte[] Rawdata,StringfileName,int sensorType)

{

byte[]bmp_head_640x480 = {

0x42,0x4D,0x38,(byte)0xC3,0x04,0x00,0x36,0x28,

0x00,(byte)0x80,0x02,(byte)0xE0,0x01,0x08,(byte)0xB0,0x12,0x0B,0x00};

byte[]bmp_head_256x360 = {

0x42,0x6C,0x68,0x01};

byte[]bmp_colmap = {00,00,00};

byte[]fixarray = new byte[1024];

for(inti=0; i<1024; i++)

fixarray[i]= 0;

try {

//FileOutputStream 用于写入诸如图像数据之类的原始字节的流。要写入字符流,请考虑使用 FileWriter。

FileOutputStreamstream = new FileOutputStream(fileName);

if( sensorType == 1) //xxx

{

stream.write(bmp_head_640x480);

stream.write(bmp_colmap,3);

stream.write(bmp_colmap,3);

for(inti=0; i<480; i++)

{

bmp_colmap[0]= bmp_colmap[1] = bmp_colmap[2] = (byte)i;

stream.write(bmp_colmap);

}

stream.write(Rawdata); //直接写入即可

}

else if( sensorType== 2 ) // xxx

{

stream.write(bmp_head_256x360);

stream.write(bmp_colmap,3);

for(inti=0; i<256; i++)

{

bmp_colmap[0]= bmp_colmap[1] = bmp_colmap[2] = (byte)i;

stream.write(bmp_colmap);

}

//BMP颠倒顺序写入即可

for(inti=0; i<360; i++)

{

stream.write(Rawdata,(360-1-i)*256,256);

}

}

stream.close();

//Log.d(TAG,"SaveRawToBmp(bytes): " + oklen);

} catch(FileNotFoundException e) {

return -2;

} catch (IOException e){

return -1;

}

return 0;

}

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...