在存儲過程中,密碼中有’(單引號),第一反應(yīng)使用轉(zhuǎn)義字符。敲上/(反斜杠),失敗告終; 百度一下如下結(jié)果,SQL 的轉(zhuǎn)義字符是:'(單引號),所以在密碼中寫’’(兩個單引號),表示一個單引號。C++ 的轉(zhuǎn)義字符是:\SQL 的轉(zhuǎn)義字符是:'(單引號)
網(wǎng)站建設(shè)公司,為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計及定制網(wǎng)站建設(shè)服務(wù),專注于企業(yè)網(wǎng)站制作,高端網(wǎng)頁制作,對成都護(hù)欄打樁機(jī)等多個行業(yè)擁有豐富的網(wǎng)站建設(shè)經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。專業(yè)網(wǎng)站設(shè)計,網(wǎng)站優(yōu)化推廣哪家好,專業(yè)seo優(yōu)化優(yōu)化,H5建站,響應(yīng)式網(wǎng)站。
一:解析普通json
1:不帶轉(zhuǎn)化字符
格式{"type":"ONLINE_SHIPS","message":{"currentTime":1400077615368,"direction":0,"id":1,"latitude":29.5506,"longitude":106.6466}}
JSONObject jsonObject = new JSONObject(jsonstr).getJSONObject("message");
System.out.println("currentTime:"+jsonObject.get("currentTime"));
System.out.println("direction:"+jsonObject.get("direction"));
System.out.println("latitude:"+jsonObject.get("latitude"));
System.out.println("longitude:"+jsonObject.get("longitude"));
jsonarray
JSONObject jo = ja.getJSONArray("cargoList").getJSONObject(0);
2:帶轉(zhuǎn)義字符的json格式
{"type":"ONLINE_SHIPS","message":"{\"currentTime\":1400077615368,\"direction\":0,\"id\":1,\"latitude\":29.5506,\"longitude\":106.6466}"}
其實(shí)也很簡單,先把它轉(zhuǎn)化成字符串就可以了
JSONObject jsonObject = new JSONObject(jsonstr);
//先通過字符串的方式得到,轉(zhuǎn)義字符自然會被轉(zhuǎn)化掉
String jsonstrtemp = jsonObject.getString("message");
System.out.println("message:"+jsonstrtemp);
jsonObject = new JSONObject(jsonstrtemp);
System.out.println("currentTime:"+jsonObject.get("currentTime"));
System.out.println("direction:"+jsonObject.get("direction"));
System.out.println("latitude:"+jsonObject.get("latitude"));
System.out.println("longitude:"+jsonObject.get("longitude"));
二:遍歷Json對象
JSONObject ports = ja.getJSONObject("ports");
IteratorString keys = ports.keys();
while(keys.hasNext()){
String key=keys.next();
String value = ports.getString(key);
}
三:使用Gjson,json與對象相互轉(zhuǎn)化
使用Gson輕松將java對象轉(zhuǎn)化為json格式
String json = gson.toJson(Object);//得到j(luò)son形式的字符串
User user = gson.fromJson(json,User.class);//得到對象
轉(zhuǎn)化成list
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lc.function.Action;
import com.lc.models.Groups;
public class MapSearch {
private void ParseData(String _data)
{
Gson gson = new Gson();
ListGroups ps = gson.fromJson(_data, new TypeTokenListGroups(){}.getType());
System.out.println(ps.get(0).getGroup_name());
}
}
在存儲過程中,密碼中有’(單引號),第一反應(yīng)使用轉(zhuǎn)義字符。敲上/(反斜杠),失敗告終;
百度一下如下結(jié)果,sql
的轉(zhuǎn)義字符是:'(單引號),所以在密碼中寫’’(兩個單引號),表示一個單引號。c++
的轉(zhuǎn)義字符是:\sql
的轉(zhuǎn)義字符是:'(單引號)
select
* fromtablewhere number like '%/%%' escape '/'...
sqlite3數(shù)據(jù)庫在搜索的時候,一些特殊的字符需要進(jìn)行轉(zhuǎn)義, 具體的轉(zhuǎn)義如下:
/ - //
' - ''
[ - /[
] - /]
% - /%
- /
_ - /_
( - /(
) - /)
需要注意的是,特殊字符并沒有用反斜杠“\”表示轉(zhuǎn)義符。
復(fù)制代碼代碼如下:
public static String sqliteEscape(String keyWord){
keyWord = keyWord.replace("/", "http://");
keyWord = keyWord.replace("'", "''");
keyWord = keyWord.replace("[", "/[");
keyWord = keyWord.replace("]", "/]");
keyWord = keyWord.replace("%", "/%");
keyWord = keyWord.replace("","/");
keyWord = keyWord.replace("_", "/_");
keyWord = keyWord.replace("(", "/(");
keyWord = keyWord.replace(")", "/)");
return keyWord;
}
加轉(zhuǎn)義字符\,或者還有一個辦法。比如回車鍵\n會被轉(zhuǎn)移。你把\n replace一下,換成別的單詞,在服務(wù)端收到這個單詞的時候,在轉(zhuǎn)換回來
Android中的TextView,本身就支持部分的Html格式標(biāo)簽。這其中包括常用的字體大小顏色設(shè)置,文本鏈接等。使用起來也比較方便,只需要使用Html類轉(zhuǎn)換一下即可。比如:
textView.setText(Html.fromHtml(str));
一、實(shí)現(xiàn)TextView里的文字有不同顏色
import android.text.Html;
TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(Html.fromHtml( "btext3:/b Text with a " + "a href=""link/a " +"created in the Java source code using HTML."));
二、TextView顯示html文件中的圖片
要讓TextView解析和顯示Html代碼。可以使用
Spanned text = Html.fromHtml(source);
tv.setText(text);
來實(shí)現(xiàn),這個用起來簡單方便。
但是,怎樣讓TextView也顯示Html中image節(jié)點(diǎn)的圖像呢?
可以看到fromHtml還有另一個重構(gòu):
fromHtml(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)
實(shí)現(xiàn)一下ImageGetter就可以讓圖片顯示了:
ImageGetter imgGetter = new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable drawable = null;
drawable = Drawable.createFromPath(source); // Or fetch it from the URL
// Important
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable
.getIntrinsicHeight());
return drawable;
}
};
當(dāng)前文章:android轉(zhuǎn)義,android轉(zhuǎn)義字符
標(biāo)題鏈接:http://chinadenli.net/article14/dsdsige.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、企業(yè)網(wǎng)站制作、云服務(wù)器、ChatGPT、虛擬主機(jī)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)