代码如下:
public JSONObject SetDataToJson()
{
JSONObject LCYDataJSON = new JSONObject();
try {
LCYDataJSON.put("MODE", lcydata.mode);
LCYDataJSON.put("date", lcydata.date);
LCYDataJSON.put("GPSSta", lcydata.gpsstat);
LCYDataJSON.put("lat", Float.toString(lcydata.lati));
LCYDataJSON.put("longg", Float.toString(lcydata.longg));
LCYDataJSON.put("ADDRESS", lcydata.addr);
LCYDataJSON.put("WIFINUM", Integer.toBinaryString(lcydata.wifinum));
} catch (JSONException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
LCYDataJSON = null;
return null;
}
JSONArray AgentArray = new JSONArray();
for(int i = 0;i <lcydata.agent.length;i++)
{
if(lcydata.agent[i]==null)
{
continue;
}
//如果是错误的,就是根本没有采集到则不进行json打包
if(lcydata.agent[i].LAC == -1&&lcydata.agent[i].CI==-1)
{
continue;
}
JSONObject AgentIF = new JSONObject();
try {
AgentIF.put("Agent",lcydata.agent[i].Agent);
AgentIF.put("LAC",lcydata.agent[i].LAC);
AgentIF.put("CI",lcydata.agent[i].CI);
AgentIF.put("FREQ",lcydata.agent[i].FREQ);
AgentIF.put("RSCP",lcydata.agent[i].RSCP);
AgentIF.put("LACCHG",lcydata.agent[i].LACCHG);
AgentIF.put("tasktype",lcydata.agent[i].tasktype);//中标类型
AgentIF.put("type",lcydata.agent[i].type);//邻区类型
AgentIF.put("NibNum",lcydata.agent[i].NibNum);//邻区个数
AgentIF.put("bSameAsBefore", lcydata.agent[i].bSameAsBefore);//是否时和上包数据重复
} catch (JSONException e1) {
// TODO Auto-generated catch block
Log.d(TAG,"AgentIF Handle Catch error");
e1.printStackTrace();
AgentArray = null;
AgentIF = null;
return null;
}
JSONArray AgentNArray = new JSONArray();
//邻区处理
for(int j=0;j<lcydata.agent[i].NibNum;j++)
{
JSONObject AgentNIF = new JSONObject();
try {
AgentNIF.put("LAC",lcydata.agent[i].agentn[j].LAC);
AgentNIF.put("CI",lcydata.agent[i].agentn[j].CI);
AgentNIF.put("RSCP",lcydata.agent[i].agentn[j].RSCP);
AgentNIF.put("tasktype", lcydata.agent[i].agentn[j].TaskType);
AgentNArray.put(AgentNIF);
AgentNIF = null;
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.d(TAG,"AgentNIF handle Catch error");
e.printStackTrace();
AgentNIF = null;
LCYDataJSON = null;
return null;
}
}
try {
AgentIF.put("AgentN",AgentNArray);
AgentArray.put(AgentIF);
LCYDataJSON.put("Agent",AgentArray);
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.d(TAG,"Add LCDataJson catch error");
e.printStackTrace();
for(int ii = 0; ii< lcydata.agent[ii].NibNum;ii++)
{
for(int m = 0 ;m<lcydata.agent[ii].NibNum;m++)
{
lcydata.agent[ii].agentn[m] = null;
}
}
LCYDataJSON = null;
return null;
}
}
//wifi信息集合
if(lcydata.wifinum > 0)
{
JSONArray WIFIArray = new JSONArray();
try
{
for(int i=0;i<lcydata.wifinum;i++)
{
JSONObject WIFIIF = new JSONObject();
//WIFIIF = lcydata.wifiinfo[i]
WIFIIF.put("SSID",lcydata.wifiinfo[i].SSID);
WIFIIF.put("MAC",lcydata.wifiinfo[i].MAC);
WIFIIF.put("RSCP",lcydata.wifiinfo[i].RSCP);
WIFIIF.put("PerCent",lcydata.wifiinfo[i].PerCent);
WIFIIF.put("IDEN",lcydata.wifiinfo[i].IDEN);
WIFIIF.put("Encrypt",lcydata.wifiinfo[i].Encrypt);
WIFIArray.put(WIFIIF);
//释放内存
lcydata.wifiinfo[i] = null;
WIFIIF = null;
}
LCYDataJSON.put("WifiInfo",WIFIArray);
WIFIArray = null;
} catch (JSONException e)
{
// TODO Auto-generated catch block
Log.d(TAG,"WIFIArray handle catch error ");
e.printStackTrace();
for(int ii = 0; ii< lcydata.agent[ii].NibNum;ii++)
{
for(int m = 0 ;m<lcydata.agent[ii].NibNum;m++)
{
lcydata.agent[ii].agentn[m] = null;
}
}
WIFIArray = null;
LCYDataJSON = null;
return null;
// System.out.println(LCYDataJSON.toJSONString());
}
}
ThreadInsertDb(LCYDataJSON);
Intent i = new Intent(Const.DATABC);//广播消息,实现类之间的交互
Bundle mBundle = new Bundle();
//进行数据反序列化,还原数据
mBundle.putString("JSONOBJSTR", LCYDataJSON.toString());
i.putExtras(mBundle);
//释放内存
LCYDataJSON = null;
//给系统配置广播数据
//给实时数据fragement广播数据
if(null!= FragmentRealData.s_context)
{
// Log.d(TAG, "Broad to FragmentRealData:"+8);
FragmentRealData.s_context.sendBroadcast(i);
i = null;
mBundle = null;
}
//因为时一个activiy--mainactivity 所以这里只广告一次就都能收到
/* if(null!=FragmentRealWifiMap.s_context)
{
FragmentRealWifiMap.s_context.sendBroadcast(i);
}
if(null!= FragmentRealDataMap.s_context)
{
//FragmentRealDataMap.s_context.sendBroadcast(i);
}*/
for(int ii = 0; ii< lcydata.agent[ii].NibNum;ii++)
{
for(int m = 0 ;m<lcydata.agent[ii].NibNum;m++)
{
lcydata.agent[ii].agentn[m] = null;
}
}
if(lcydata.wifinum > 0)
{
for(int l = 0; l < lcydata.wifinum;l++)
{
lcydata.wifiinfo[l] = null;
}
}
System.gc();
return LCYDataJSON;
}
请大神门帮看看,哪里出问题了!!![图片说明](https://img-ask.csdn.net/upload/201601/20/1453252530_369935.png)