[英]find the value between quotation marks in a string and store the value in a variable
[英]How to create a string variable with Quotation marks in it's value?
我有以下文字:
"{
"iv": "QaVlP3rzrSNw3oRLqmXv7Q",
"v": 1,
"iter": 1000,
"ks": 128,
"ts": 64,
"mode": "ccm",
"adata": "",
"cipher": "aes",
"salt": "ffGgwesLMEg",
"ct": "5QjHDbwuLIgYZFWvgIH4J5WZI514zJR0ucsmQ0jljYaOgCKNOWlnrpO0ipEVjQiA7hHfk7T7nXcjN2Yo10U+dGY5DMS+OfvZiGo6/kbBkgpFWEz28uwUl1zIRJ6NBfxULbMjyoUwPuxV05r87U5+H+WEuEiKCP7HWgQH0d68a8AEsvoVah1pDUWlYXom8+TqvTHwmm5Dyyv84h3JN8KHSEnum8ORXDGGNthif3LzirAULRzH0PlsJYrgtj+yOoIWuS0wAKPgwxRkAVchjRoFqEgwfYp+wawLC6oWwj8Mq1ERVyk"
}"
如果我在同一目錄中使用具有此值的文本文件,請使用jQuery:
var text = jQuery.get('http://localhost/text.txt'); //This convert text to an Object...
和
JSON.stringify(text) // returns "{"readyState":1}"
那么,有什么方法可以將此文本保存到變量中?
您需要使用回調來處理響應並將響應類型設置為json
。
jQuery.get('http://localhost/text.txt', function(res){
console.log(res);
}, 'json');
或改為使用jQuery.getJSON
方法。
jQuery.getJSON('http://localhost/text.txt', function(res){
console.log(res);
});
var json_variable = JSON.parse(jQuery.get('http://localhost/text.txt'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.