JSONArray jsonArray解析

 try {
            JSONArray jsonArray = new JSONObject(serviceMessage).getJSONArray("candidateList");
            for(int i=0; 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, 0x00, 0x00, 0x00, 0x00, 0x36, 0x04, 0x00,0x00, 0x28, 0x00,

                           0x00,0x00, (byte)0x80, 0x02, 0x00, 0x00, (byte)0xE0, 0x01, 0x00, 0x00, 0x01, 0x00,0x08, 0x00, 0x00, 0x00,

                           0x00,0x00, 0x02, (byte)0xB0, 0x04, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,0x00, 0x00, 0x00};

        byte[]bmp_head_256x360 = {

                           0x42,0x4D, 0x36, 0x6C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x04, 0x00, 0x00,0x28, 0x00,

                           0x00,0x00, 0x00, 0x01, 0x00, 0x00, 0x68, 0x01, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00,0x00, 0x00,

                           0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x01};   

        byte[]bmp_colmap = {00, 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,0, 3);

                                     stream.write(bmp_colmap,0, 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,0, 3);

                                     stream.write(bmp_colmap,0, 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;

    }


你可能感兴趣的:(Android)