如何将String字符串转变为json格式

字符串Data的数据格式为{"password":"123456"},encodeConfig的值为password

如何将Data的值由String转变为Json呢?

我们需要利用jettison中的JSONObject类,需要导入的类如下:

import org.codehaus.jettison.json.JSONObject;

//将String字符串转变为Json

JSONObject jsonObject=new JSONObject(Data);

//因为encodeConfig的值为password,通过getString方法可以拿到123456

toEncode = jsonObject.getString(encodeConfig);

你可能感兴趣的:(如何将String字符串转变为json格式)