包是 import net.sf.json.JSONObject;
查询出来的String值 [{“address”:“爱上深呼吸”,“latitude”:“29.677783”,“longitude”:“115.95288”}]
/** (non-Javadoc)
* <p>Title: fingProjectCoordinates</p>
* <p>Description: </p>
* @author 爱上深呼吸
* @since 2019年11月18日上午9:52:41
* @param projectId
* @return
* @see com.rionsoft.gomeet.api.Scaffod.biz.SmartsiteColumnManagementService#fingProjectCoordinates(java.lang.String)
*/
@Override
public ResultMsg fingProjectCoordinates(String projectId) {
try {
SmartsiteColumnManagementImg smpid =smartsiteColumnManagementMapper.fingProjectCoordinates(projectId);
// String a=smpid.getCoordinates().replace("[","").replace("]","");
// JSONObject json = JSONObject.fromObject(a);
JSONObject json = JSONObject.fromObject(smpid.getCoordinates());
System.err.println(json.get("latitude"));
} catch (Exception e) {
// TODO: handle exceptio
e.printStackTrace();
}
return null;
}
net.sf.json.JSONException: A JSONObject text must begin with ‘{’ at character 1
这个会报必须以{开头所以我们只要把中括号替换掉就可以
/** (non-Javadoc)
* <p>Title: fingProjectCoordinates</p>
* <p>Description: </p>
* @author 爱上深呼吸
* @since 2019年11月18日上午9:52:41
* @param projectId
* @return
* @see com.rionsoft.gomeet.api.Scaffod.biz.SmartsiteColumnManagementService#fingProjectCoordinates(java.lang.String)
*/
@Override
public ResultMsg fingProjectCoordinates(String projectId) {
try {
SmartsiteColumnManagementImg smpid =smartsiteColumnManagementMapper.fingProjectCoordinates(projectId);
String a=smpid.getCoordinates().replace("[","").replace("]","");
JSONObject json = JSONObject.fromObject(a);
// JSONObject json = JSONObject.fromObject(smpid.getCoordinates());
System.err.println(json.get("latitude"));
} catch (Exception e) {
// TODO: handle exceptio
e.printStackTrace();
}
return null;
}
这样就取到拉