我必须将xml代码转换为Json。我试过使用这段代码:
public String getJSON(String toConvert) {
String jsonString = null;
try {
JSONObject xmlJSONObj = XML.toJSONObject(toConvert);
jsonString = xmlJSONObj.toString();
} catch (JSONException je) {
System.out.println(je.toString());
}
return jsonString;
}
它可以工作,但只适用于短字符串。我应该怎么做才能使用很长的String?
答案 0 :(得分:0)
将xml转换为json没有问题。那部分(方法before_action :authenticate_user!
)是正确的。
getJson
java编译错误是问题所在。您可以解决此问题,请查看that question and answers。