本文介绍了转换的InputStream的JSONObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我转换的InputStream使用下面的code的JSONObject。我的问题是,有没有为InputStream转换为JSONObject的任何简单的方法。如果不这样做的InputStream - >的BufferedReader - >的StringBuilder - >环 - > JSONObject.toString()。
的InputStream inputStreamObject = PositionKeeperRequestTest.class.getResourceAsStream(jsonFileName);
的BufferedReader的StreamReader =新的BufferedReader(新的InputStreamReader(inputStreamObject,UTF-8));
StringBuilder的responseStrBuilder =新的StringBuilder();
字符串inputStr;
而((inputStr = streamReader.readLine())!= NULL)
responseStrBuilder.append(inputStr);
的JSONObject的JSONObject =新的JSONObject(responseStrBuilder.toString());
解决方案
使用JsonReader为了解析InputStream的。请参阅API里面的例子: http://developer.android.com/reference/android/util/JsonReader.html
I am converting InputStream to JSONObject using following code. My question is, is there any simple way to convert InputStream to JSONObject. Without doing InputStream -> BufferedReader -> StringBuilder -> loop -> JSONObject.toString().
InputStream inputStreamObject = PositionKeeperRequestTest.class.getResourceAsStream(jsonFileName);
BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStreamObject, "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
responseStrBuilder.append(inputStr);
JSONObject jsonObject = new JSONObject(responseStrBuilder.toString());
解决方案
use JsonReader in order to parse the InputStream. See example inside the API:http://developer.android.com/reference/android/util/JsonReader.html
这篇关于转换的InputStream的JSONObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!