本文整理汇总了Java中org.json.JSONTokener.nextValue方法的典型用法代码示例。如果您正苦于以下问题:Java JSONTokener.nextValue方法的具体用法?Java JSONTokener.nextValue怎么用?Java JSONTokener.nextValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONTokener
的用法示例。
在下文中一共展示了JSONTokener.nextValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createResponsesFromString
import org.json.JSONTokener; //导入方法依赖的package包/类
static List<Response> createResponsesFromString(String responseString, HttpURLConnection connection,
RequestBatch requests, boolean isFromCache) throws FacebookException, JSONException, IOException {
JSONTokener tokener = new JSONTokener(responseString);
Object resultObject = tokener.nextValue();
List<Response> responses = createResponsesFromObject(connection, requests, resultObject, isFromCache);
Logger.log(LoggingBehavior.REQUESTS, RESPONSE_LOG_TAG, "Response\n Id: %s\n Size: %d\n Responses:\n%s\n",
requests.getId(), responseString.length(), responses);
return responses;
}
示例2: createResponsesFromString
import org.json.JSONTokener; //导入方法依赖的package包/类
static List<GraphResponse> createResponsesFromString(
String responseString,
HttpURLConnection connection,
GraphRequestBatch requests
) throws FacebookException, JSONException, IOException {
JSONTokener tokener = new JSONTokener(responseString);
Object resultObject = tokener.nextValue();
List<GraphResponse> responses = createResponsesFromObject(
connection,
requests,
resultObject);
Logger.log(
LoggingBehavior.REQUESTS,
RESPONSE_LOG_TAG,
"Response\n Id: %s\n Size: %d\n Responses:\n%s\n",
requests.getId(),
responseString.length(),
responses);
return responses;
}
示例3: Test
import org.json.JSONTokener; //导入方法依赖的package包/类
public static void Test(String LoginName, String UserPwd) {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://eip.lansum.com/Handler/ILansumEip.ashx?op=GetRegional");
get.setHeader("Cookie", "UserName=" + LoginName + ";UserPwd=" + UserPwd + "");
// HttpGet get = new
// HttpGet("http://eip.lansum.com/Handler/ILansumEip.ashx?op=GetRegional");
HttpResponse response;
try {
response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
InputStream is;
is = response.getEntity().getContent();
String result = inStream2String(is);
JSONTokener jsonParser = new JSONTokener(result);
// 此时还未读取任何json文本,直接读取就是一个JSONObject对象。
// 如果此时的读取位置在"name" : 了,那么nextValue就是"yuanzhifei89"(String)
JSONObject person = (JSONObject) jsonParser.nextValue();
// 接下来的就是JSON对象的操作了
int state = person.getInt("state");
// String state = jsonObj.getString("state");
Log.d("ws", state + "");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: decodeObject
import org.json.JSONTokener; //导入方法依赖的package包/类
public static Map<String,Object> decodeObject(String json){
Map<String,Object> result=new HashMap<>();
JSONTokener readFrom=new JSONTokener(json);
try {
Object object = readFrom.nextValue();
if(object instanceof JSONObject){
result=decodingObject((JSONObject)object);
}
}catch (JSONException ex){
LogUtils.e(ex);
}finally {
return result;
}
}
示例5: decodeArray
import org.json.JSONTokener; //导入方法依赖的package包/类
public static List<Object> decodeArray(String json){
List<Object> result=new ArrayList<>();
JSONTokener readFrom=new JSONTokener(json);
try {
Object object = readFrom.nextValue();
if(object instanceof JSONArray){
result = decodingArray((JSONArray)object);
}
}catch (JSONException ex){
LogUtils.e(ex);
}finally {
return result;
}
}
示例6: doTranslate
import org.json.JSONTokener; //导入方法依赖的package包/类
public void doTranslate() throws IOException, JSONException {
// 格式化需要翻译的内容为UTF-8编码
String str_utf = URLEncoder.encode(str, "UTF-8");
// 百度翻译api
String str_url = "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=GOr7jiTs5hiQvkHqDNg4KSTV&q="
+ str_utf + "&from=" + fromString + "&to=" + toString;
// 将api网址转化成URL
URL url_word = new URL(str_url);
// 连接到该URL
URLConnection connection = (URLConnection) url_word.openConnection();
// 获取输入流
InputStream is = connection.getInputStream();
// 转化成读取流
InputStreamReader isr = new InputStreamReader(is);
// 转化成缓冲读取流
BufferedReader br = new BufferedReader(isr);
// 每行的内容
String line;
// 字符串处理类
StringBuilder sBuilder = new StringBuilder();
// 读取每行内容
while ((line = br.readLine()) != null) {
// 在字符串末尾追加内容
sBuilder.append(line);
}
/**
* 单词解析
*/
JSONTokener jtk = new JSONTokener(sBuilder.toString());
JSONObject jObject = (JSONObject) jtk.nextValue();
JSONArray jArray = jObject.getJSONArray("trans_result");
Log.i("TAG", url_word.toString());
Log.i("TAG", jObject.toString());
JSONObject sub_jObject_1 = jArray.getJSONObject(0);
// dst对应的内容就是翻译结果
result = sub_jObject_1.getString("dst");
br.close();
isr.close();
is.close();
}