我正在尝试下载json包含斯洛文尼亚字符的文件,在将json文件作为字符串下载时,我将获得如下json数据中指定的特殊字符
"send_mail": "Po?lji elektronsko sporocilo.",
"str_comments_likes": "Komentarji, v?ecki in mejniki",
Run Code Online (Sandbox Code Playgroud)
我正在使用的代码
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
try {
InputStream input1 = new BufferedInputStream(url.openStream(), 300);
String myData = "";
BufferedReader r = new BufferedReader(new InputStreamReader(input1));
StringBuilder totalValue = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
totalValue.append(line).append('\n');
}
input1.close();
String value = totalValue.toString();
Log.v("To Check Problem from http paramers", value);
} catch (Exception e) {
Log.v("Exception Character Isssue", "" …Run Code Online (Sandbox Code Playgroud) 我有一个数组资源。我想进行测试以读取和解析来自 xml 资源的值。这是代码。
<string-array name="names">
<item>Name1[?]200</item>
<item>Name2[?]125</item>
<item>Name3[?]142</item>
</string-array>
Run Code Online (Sandbox Code Playgroud)
我想捕获上面的字符串资源并像下面的测试用例一样解析。但我达不到。
@RunWith(MockitoJUnitRunner.class)
public class ReadAndParseNamesTest {
@Mock
private Context mockApplicationContext;
@Mock
private Resources mockContextResources;
@Test
public void readAndParseNamesTest() {
MockitoAnnotations.initMocks(this);
when(mockApplicationContext.getResources()).thenReturn(mockContextResources);
String[] marray = {"mock main class"};
when(mockContextResources.getStringArray(R.array.allah_names))
.thenReturn(marray);
for(int i = 0;i<marray.length;i++){
String[] deger = marray[i].split("[?]");
System.out.println("Deger "+i+": "+deger[0] + " "+ deger[1]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到java.lang.ArrayIndexOutOfBoundsException: 1异常,因为我无法获得实际值。任何帮助将不胜感激。谢谢你。