如何在java中的字符串中存储URL

时间:2016-01-17 02:50:01

标签: java json

我一直试图解析json对象的特定部分。更具体地说,我提取http://www.dprobuk.com/api/get_post?id=677&include=title,id,content这是一个JSON数组,并且我已经提取了"内容"键。所以对我来说真正的问题现在在内容键中,有一个textarea标签,其内容我想将它存储在字符串中。但是这样做我得到了非法的转义序列错误。

实施例: String st =" http:\ / \ / www.dprobuk.com/"所以它自然是非法的,是否有一些其他方式在java中存储上面的字符串?或者从上面的JSON数组中分割textarea的其他方法吗?

This is the json array which i am trying

<div id="my"></div><script>
var st="<textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">"+
"\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;title&gt;HTML Form using Bootstrap&lt;\/title&gt;\r\n        &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt; \r\n        &lt;link href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.5\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\r\n        &lt;script src=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.5\/js\/bootstrap.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body style=\"background:url(pattern1.jpg);\"&gt;    \r\n        &lt;div class=\"container\"&gt;\r\n            &lt;div class=\"row\"&gt;\r\n                &lt;div class=\"col-lg-8 col-lg-offset-2\"&gt;\r\n                    &lt;h1&gt;This is a Sample Form Using BootStrap&lt;\/h1&gt;\r\n                    &lt;br\/&gt;&lt;br\/&gt;\r\n                    &lt;form name=\"sentMessage\" id=\"contactForm\" novalidate&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Name&lt;\/label&gt;\r\n                                &lt;input type=\"text\" class=\"form-control\" placeholder=\"Name\" id=\"name\" required data-validation-required-message=\"Please enter your name.\"&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Email Address&lt;\/label&gt;\r\n                                &lt;input type=\"email\" class=\"form-control\" placeholder=\"Email Address\" id=\"email\" required data-validation-required-message=\"Please enter your email address.\"&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Phone Number&lt;\/label&gt;\r\n                                &lt;input type=\"tel\" class=\"form-control\" placeholder=\"Phone Number\" id=\"phone\" required data-validation-required-message=\"Please enter your phone number.\"&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Message&lt;\/label&gt;\r\n                                &lt;textarea rows=\"5\" class=\"form-control\" placeholder=\"Message\" id=\"message\" required data-validation-required-message=\"Please enter a message.\"&gt;&lt;\/textarea&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;br&gt;\r\n                        &lt;div class=\"row\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12\"&gt;\r\n                                &lt;button type=\"submit\" class=\"btn btn-success btn-lg\"&gt;Send&lt;\/button&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                    &lt;\/form&gt;\r\n                &lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;"+
"<\/textarea>";
var ta = document.getElementById('my');
ta.innerHTML=st;</script>

上面的代码有效,但是当我在Java中使用相同的变量st作为字符串时,它无法编译!

class SimpleCode
{
public static void main(String []as)
{
    String st="<textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">"+
    "\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;title&gt;HTML Form using Bootstrap&lt;\/title&gt;\r\n        &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt; \r\n        &lt;link href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.5\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\r\n        &lt;script src=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.5\/js\/bootstrap.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body style=\"background:url(pattern1.jpg);\"&gt;    \r\n        &lt;div class=\"container\"&gt;\r\n            &lt;div class=\"row\"&gt;\r\n                &lt;div class=\"col-lg-8 col-lg-offset-2\"&gt;\r\n                    &lt;h1&gt;This is a Sample Form Using BootStrap&lt;\/h1&gt;\r\n                    &lt;br\/&gt;&lt;br\/&gt;\r\n                    &lt;form name=\"sentMessage\" id=\"contactForm\" novalidate&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Name&lt;\/label&gt;\r\n                                &lt;input type=\"text\" class=\"form-control\" placeholder=\"Name\" id=\"name\" required data-validation-required-message=\"Please enter your name.\"&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Email Address&lt;\/label&gt;\r\n                                &lt;input type=\"email\" class=\"form-control\" placeholder=\"Email Address\" id=\"email\" required data-validation-required-message=\"Please enter your email address.\"&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Phone Number&lt;\/label&gt;\r\n                                &lt;input type=\"tel\" class=\"form-control\" placeholder=\"Phone Number\" id=\"phone\" required data-validation-required-message=\"Please enter your phone number.\"&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;div class=\"row control-group\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12 floating-label-form-group controls\"&gt;\r\n                                &lt;label&gt;Message&lt;\/label&gt;\r\n                                &lt;textarea rows=\"5\" class=\"form-control\" placeholder=\"Message\" id=\"message\" required data-validation-required-message=\"Please enter a message.\"&gt;&lt;\/textarea&gt;\r\n                                &lt;p class=\"help-block text-danger\"&gt;&lt;\/p&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;br&gt;\r\n                        &lt;div class=\"row\"&gt;\r\n                            &lt;div class=\"form-group col-xs-12\"&gt;\r\n                                &lt;button type=\"submit\" class=\"btn btn-success btn-lg\"&gt;Send&lt;\/button&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                    &lt;\/form&gt;\r\n                &lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;"+
    "<\/textarea>";
    System.out.println(st);
}
}

所以我想知道任何其他程序让它起作用吗?

1 个答案:

答案 0 :(得分:1)

pom.xml