如何将Javascript对象转换为url字符串?

时间:2017-10-17 18:31:48

标签: javascript object

我有一个Javascript对象,如:

var obj = {
    name: "Omer",
    age: 30,
    siblings: 3
} 

有没有办法可以把它转换成这样的字符串:

name=Omer&age=30&siblings=3

我已经使用JSON.stringify()进行了尝试,但它并未向我提供我正在寻找的结果。

结果如下:

{"name":"Omer","age":"30","siblings":"3"}

2 个答案:

答案 0 :(得分:4)

您可以使用class MyViewController: UIViewController, WKNavigationDelegate { // standard UIView, added in Storyboard @IBOutlet weak var webViewHolder: UIView! // instance of WKWebView let wkWebView: WKWebView = { let v = WKWebView() v.translatesAutoresizingMaskIntoConstraints = false return v }() override func viewDidLoad() { super.viewDidLoad() // add the WKWebView to the "holder" UIView webViewHolder.addSubview(wkWebView) // pin to all 4 edges wkWebView.topAnchor.constraint(equalTo: webViewHolder.topAnchor, constant: 0.0).isActive = true wkWebView.bottomAnchor.constraint(equalTo: webViewHolder.bottomAnchor, constant: 0.0).isActive = true wkWebView.leadingAnchor.constraint(equalTo: webViewHolder.leadingAnchor, constant: 0.0).isActive = true wkWebView.trailingAnchor.constraint(equalTo: webViewHolder.trailingAnchor, constant: 0.0).isActive = true // load a URL into the WKWebView if let url = URL(string: "https://google.com") { wkWebView.load(URLRequest(url: url)) } // from here on out, use wkWebView just as if you had added it in your storyboard } } array#map



join()




答案 1 :(得分:1)



var ob = {
   key1: 'value1',
   key2: 'value2',
   key3: 'value3'
}

var str = "";
for (var key in ob) {
    if (str != "") {
        str += "`";
    }
    str += key + "=" + ob[key];
}

alert(str);