Java中js解析json数据据有错,A JSONObject text must begin with '{',可是我明明有.而且在线解析json也没错.

Redmine Java Api -
org.json.JSONException: A JSONObject text must begin with '{' at character 1
When I try run this code (The Issue example is taken from this web
RedmineManager redmineManager = new RedmineManager("http://something.cz", "somekey"); //I changed these two parameters for security reasons when paste here
System.out.println(redmineManager.getProjects().size()); //this works fine
Issue issueToCreate = new Issue();
issueToCreate.setSubject("This is the summary line 123");
Issue newIssue = redmineManager.createIssue("test-project", issueToCreate); //this line throws exception
It ends with this exception
Exception in thread "main" com.taskadapter.redmineapi.RedmineFormatException: org.json.JSONException: A JSONObject text must begin with '{' at character 1
at com.taskadapter.redmineapi.internal.Transport.parseResponse(Transport.java:456)
at com.taskadapter.redmineapi.internal.Transport.addObject(Transport.java:186)
at com.taskadapter.redmineapi.RedmineManager.createIssue(RedmineManager.java:135)
at javaapplication146.JavaApplication146.main(JavaApplication146.java:27)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at character 1
at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
at org.json.JSONObject.&init&(JSONObject.java:179)
at org.json.JSONObject.&init&(JSONObject.java:402)
at com.taskadapter.redmineapi.internal.RedmineJSONParser.getResponseSingleObject(RedmineJSONParser.java:609)
at com.taskadapter.redmineapi.internal.Transport.parseResponse(Transport.java:454)
... 3 more
Java Result: 1
The same behaviour is for any other "get some objects" (which works) and for "create some objects" (which does not).
I am using maven with its dependency for version 1.23, however I tried 1.12.0 and same exception was thrown.
We are using latest redmine 2.5.1.stable, however based on stacktrace, the communication between redmine web and this redmine api does not happen as the exception is thrown in "parseRespone" part of application.EDIT: I actually found the answer. I can't close the question as I am new. I was able to use Array.getString(i) to return the string value needed. Thanks for all the help.
I have JSON like this:
"example1",
"example2",
"example3",
"example4"
And I am trying to get the string value of those objects without using a key. How can I do that? The getString() for jsonObject require a key and I don't have one.
解决方案 I assume that you have a file :/home/user/file_001.json
the file contains this : `
{"age":34,"name":"myName","messages":["msg 1","msg 2","msg 3"]}
Now let's write a program that reads the file : /home/user/file_001.json
and converts its content to a java JSONObject.
package org.xml.
import java.io.FileNotFoundE
import java.io.FileR
import java.io.IOE
import java.util.I
import org.json.simple.JSONA
import org.json.simple.JSONO
import org.json.simple.parser.JSONP
import org.json.simple.parser.ParseE
public class JsonSimpleRead
@SuppressWarnings("unchecked")
public static void main(String[] args)
JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader("/home/user/file_001.json"));
JSONObject jsonObject = (JSONObject)
String name = (String) jsonObject.get("name");
System.out.println(name);
long age = (Long) jsonObject.get("age");
System.out.println(age);
JSONArray msg = (JSONArray) jsonObject.get("messages");
Iterator&String& iterator = msg.iterator();
while (iterator.hasNext())
System.out.println(iterator.next());
catch (FileNotFoundException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
catch (ParseException e)
e.printStackTrace();
本文地址: &
编辑:其实,我找到了答案。因为我是新的我无法关闭的问题。我能够使用Array.getString(i)返回所需的字符串值。感谢所有帮助。我有JSON是这样的:
“清单”:
“示例3”,
]} 和我试图获得这些对象的字符串值,而无需使用钥匙。我该怎么办呢?在的getString()为JSONObject的要求的关键,我没有之一。解决方案 我假设你有一个文件: /home/user/file_001.json
该文件包含此:`
{“时代”:34,“名”:“MYNAME”,“消息”:“MSG 1”,“味精2”,“味精3”]} 现在让我们写一个程序,读取该文件: /home/user/file_001.json 其内容转换为一个java 的JSONObject 。 包org.xml.进口java.io.FileNotFoundE进口java.io.FileR进口java.io.IOException异常;进口java.util.Iterator的;进口org.json.simple.JSONA进口org.json.simple.JSONO进口org.json.simple.parser.JSONP进口org.json.simple.parser.ParseE
公共类JsonSimpleRead
@燮pressWarnings(“未登记”)
公共静态无效的主要(字串[] args)
JSONParser分析器=新JSONParser();
obj对象= parser.parse(新的FileReader(“/ home / user中/ file_001.json”));
的JSONObject的JSONObject =(JSONObject的)目标文件;
字符串名称=(字符串)jsonObject.get(“名称”);
的System.out.println(名);
长龄=(长)jsonObject.get(“时代”);
的System.out.println(年龄);
JSONArray味精=(JSONArray),其中jsonObject.get(“信息”);
迭代器<串GT;迭代= msg.iterator();
而(iterator.hasNext())
的System.out.println(iterator.next());
赶上(FileNotFoundException异常E)
e.printStackTrace();
赶上(IOException异常E)
e.printStackTrace();
赶上(ParseException的E)
e.printStackTrace();
本文地址: &
扫一扫关注官方微信Redmine Java Api - org.json.JSONException: A JSONObject text must begin with '{' at character 1 - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
When I try run this code (The Issue example is taken from this web
RedmineManager redmineManager = new RedmineManager("http://something.cz", "somekey"); //I changed these two parameters for security reasons when paste here
System.out.println(redmineManager.getProjects().size()); //this works fine
Issue issueToCreate = new Issue();
issueToCreate.setSubject("This is the summary line 123");
Issue newIssue = redmineManager.createIssue("test-project", issueToCreate); //this line throws exception
It ends with this exception
Exception in thread "main" com.taskadapter.redmineapi.RedmineFormatException: org.json.JSONException: A JSONObject text must begin with '{' at character 1
at com.taskadapter.redmineapi.internal.Transport.parseResponse(Transport.java:456)
at com.taskadapter.redmineapi.internal.Transport.addObject(Transport.java:186)
at com.taskadapter.redmineapi.RedmineManager.createIssue(RedmineManager.java:135)
at javaapplication146.JavaApplication146.main(JavaApplication146.java:27)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at character 1
at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
at org.json.JSONObject.&init&(JSONObject.java:179)
at org.json.JSONObject.&init&(JSONObject.java:402)
at com.taskadapter.redmineapi.internal.RedmineJSONParser.getResponseSingleObject(RedmineJSONParser.java:609)
at com.taskadapter.redmineapi.internal.Transport.parseResponse(Transport.java:454)
... 3 more
Java Result: 1
The same behaviour is for any other "get some objects" (which works) and for "create some objects" (which does not).
I am using maven (
) with its dependency for version 1.23, however I tried 1.12.0 and same exception was thrown.
We are using latest redmine 2.5.1.stable, however based on stacktrace, the communication between redmine web and this redmine api does not happen as the exception is thrown in "parseRespone" part of application.
9,45062252
Unfortunatelly, it looks like this issue remains unsolve (or unsolvable), based on discussion with library owner :
However GET requests work. And for UPDATE/CREATE, you can use pure API like following. WARNING : Disabling SSL is dangerous, use only for testing purposes (like "does it even work?")
import java.io.BufferedR
import java.io.IOE
import java.io.InputStreamR
import java.io.OutputStreamW
import java.io.StringW
import java.net.HttpURLC
import java.net.MalformedURLE
import java.net.URL;
import javax.net.ssl.HttpsURLC
import javax.net.ssl.TrustM
import javax.net.ssl.X509TrustM
import javax.net.ssl.*;
import java.security.SecureR
import java.security.cert.X509C
* @author libik
public class JavaApplication147 {
* @param args the command line arguments
public static void main(String[] args) throws Exception {
disableCertificateValidation();
URL url = new URL("https://redmine.***.cz/issues.xml");
HttpsURLConnection httpCon = (HttpsURLConnection) url.openConnection();
httpCon.setRequestProperty("X-Redmine-API-Key", "*****");
httpCon.setRequestProperty("Content-Type", "application/xml");
httpCon.setDoOutput(true);
httpCon.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(
httpCon.getOutputStream());
out.write("&?xml version=\"1.0\"?&\n" +
"&issue&\n" +
&project_id&pan-unicorn-bot&/project_id&\n" +
&subject&Created from netbeans by name without priority&/subject&\n" +
"&/issue&");
out.close();
BufferedReader br =
StringBuilder sb = new StringBuilder();
br = new BufferedReader(new InputStreamReader(httpCon.getInputStream()));
while ((line = br.readLine()) != null) {
sb.append(line);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
br.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println(sb.toString());
public static void disableCertificateValidation() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
public void checkClientTrusted(X509Certificate[] certs, String authType) {
public void checkServerTrusted(X509Certificate[] certs, String authType) {
// Ignore differences between given hostname and certificate hostname
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hv);
} catch (Exception e) {
9,45062252
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledbeginwith 完美作业网 www.wanmeila.com
sql server 2005有没有类似java beginWith的函数 CREATE PROC test(@name)asbeginif @name like 'NEW%'select 1elseselect 2end没有此函数,可以用LIKE关键字
首先用to begin with,那后面第二第三怎么说 第二第三可以说:secondly,thirdly当然,你也可以说next,then,what's more,moreover,in addition等然后结尾总结时可以用 last but not least等.
安卓开发中 drawble 里图片的名称能否为数字? The resource name must begin with a character.数字不可以出现在名称的最前面,必须是字符。
so many of my smiles begin with you啥意思 感觉很不地道的英语。太多的微笑在从你开始。
我读取json数据明明是 { 开头,}结尾的。可android为啥总是报错:JSONObject text must begin with '{' a 120分{"success":true,&msg":"成功"} 这样的格式没有问题的,它里面的key/value你也给套上引号,value是数字的不用,再试试
begin at和begin with的区别 at后面通常加时间,而with后面可以加名词,代词,动名词。
java 中用dom解析xml文件出错啦,请问是什么错啊??求帮助,谢谢啦!! XML文件结构不对
37.We could begin with Z and write the dictionary in ____ order.A.irregularB.reverseC.disorderlyD.unusual38.A ___ woman wouldn't weep just because her husband had forgotten her birthday.A.emotionalB.rationalC.unreasonableD.irrational39.1,3,5,7 and 9 37.B38.B39.A40.C41.B42.A43.D44.D45.C
cisco 管道我的怎么用不到 R1#show running-config | ?append
Append redirected output to URL (URLs supporting append operationonly)begin
Begin with the line that matchesexclude
Exclude lines that matchinclude
Include lines that matchredirect
Redirect output to URL
Filter a section of outputtee
Copy output to URLR1#show running-config |可能是你路由器的版本不支持,上面是我在我的路由器上查询得到的结果,管道可用
vhdl中的或 “or” 和 “|” 有什么区别 VHDL 只有OR,没有|。|是C语言中得或运算,VHDL没有此语法}

我要回帖

更多关于 jquery解析json数据 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信