我试图运行以序列化JSON响应,但我在“let json = ...”行上收到错误。错误是“对成员'的模糊引用'jsonObject(with:options :)'”。如果有人知道如何解决这个问题,我会知道如何解决这个问题
Alamofire.request("https://httpbin.org/get").responseJSON { response in
if let JSON = response.result.value {
do {
let json = try JSONSerialization.jsonObject(with: response.result.value!, options: .allowFragments)
} catch {
print ()
}
print("JSON: \(JSON)")
}
}
答案 0 :(得分:1)
因为function menuItemListener( link ) {
var side = link.getAttribute("data-action");
if (side == 'Mark as A' || side == 'Mark as B') {
highlighter(side);
$.ajax({
method: "POST",
url: "http://localhost:3000/",
dataType: "json",
data: JSON.stringify({"rangyobject" : rangy.saveSelection()}),
contentType: "application/json; charset=utf-8",
success: function(result) {
console.log('yei');
}
});
}
toggleMenuOff();
}
function loadHighlights () {
window.addEventListener("load", function load(event){
$.ajax({
method: "GET",
url: "http://localhost:3000/ranges",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(result) {
console.log('loadHighlights results: ', result[0].rangyObject);
rangy.restoreSelection(result[0].rangyObject);
}
});
是字典response.result.value
的类型,而不是预期的__NSDictionaryI
数据。您可以轻松地从jsonObject
检索值,无需转换为json,例如:JSON