gpt4 book ai didi

swift - Alamofire 之后解析 JSON

转载 作者:行者123 更新时间:2023-11-30 12:21:37 25 4
gpt4 key购买 nike

解析 JSON feed 时遇到困难:

{
device = {
DMExempt = false;
MRISafetyStatus = "Labeling does not contain MRI Safety Information";
brandName = "Genius 2";
catalogNumber = 303000;
companyName = "Covidien LP";
contacts = {
customerContact = {
email = "covidien.udi@covidien.com";
phone = "+1(508)261-8000";
phoneExtension = "<null>";
};
};
deviceCombinationProduct = false;
deviceCommDistributionEndDate = "<null>";
deviceCommDistributionStatus = "In Commercial Distribution";
deviceCount = 1;
deviceDescription = "Tympanic Thermometer and Base";
deviceHCTP = false;
deviceKit = false;
devicePublishDate = "2016-09-24";
deviceRecordStatus = Published;
deviceSizes = "<null>";
donationIdNumber = false;
environmentalConditions = {
storageHandling = (
{
storageHandlingHigh = {
unit = "Percent (%) Relative Humidity";
value = 95;
};
storageHandlingLow = {
unit = "Percent (%) Relative Humidity";
value = 0;
};
storageHandlingSpecialConditionText = "<null>";
storageHandlingType = "Storage Environment Humidity";
},
{
storageHandlingHigh = {
unit = "";
value = "";
};
storageHandlingLow = {
unit = "";
value = "";
};
storageHandlingSpecialConditionText = "Keep dry;AVOID DIRECT SUNLIGHT";
storageHandlingType = "Special Storage Condition, Specify";
},
{
storageHandlingHigh = {
unit = "Degrees Fahrenheit";
value = 131;
};
storageHandlingLow = {
unit = "Degrees Fahrenheit";
value = "-13";
};
storageHandlingSpecialConditionText = "<null>";
storageHandlingType = "Storage Environment Temperature";
},
{
storageHandlingHigh = {
unit = "Degrees Fahrenheit";
value = 91;
};
storageHandlingLow = {
unit = "Degrees Fahrenheit";
value = 61;
};
storageHandlingSpecialConditionText = "<null>";
storageHandlingType = "Handling Environment Temperature";
}
);
};
expirationDate = false;
gmdnTerms = {
gmdn = {
gmdnPTDefinition = "A hand-held, battery-powered, electronic instrument designed to measure a patient's body temperature. It may comprise an electronic unit with an attached probe or be a single unit (shaped like an ordinary hand-held capillary thermometer) that detects and converts the changes in temperature into variations of some electrical characteristic, e.g., resistance or voltage. These variations of the electrical characteristics are processed in the electronic circuits and in turn displayed, for a short period, as temperature readings. Thereafter the display will automatically turn off or go into standby mode. This is a reusable device.";

gmdnPTName = "Intermittent electronic patient thermometer";
};
};
identifiers = {
identifier = (
{
containsDINumber = 20884521099798;
deviceId = 10884521099791;
deviceIdIssuingAgency = GS1;
deviceIdType = Package;
pkgDiscontinueDate = "<null>";
pkgQuantity = 12;
pkgStatus = "In Commercial Distribution";
pkgType = CASE;
},
{
containsDINumber = "<null>";
deviceId = 20884521099798;
deviceIdIssuingAgency = GS1;
deviceIdType = Primary;
pkgDiscontinueDate = "<null>";
pkgQuantity = "<null>";
pkgStatus = "<null>";
pkgType = "<null>";
}
);
};
labeledContainsNRL = false;
labeledNoNRL = false;
lotBatch = true;
manufacturingDate = false;
otc = false;
premarketExempt = false;
productCodes = {
fdaProductCode = {
productCode = FLL;
productCodeName = "Thermometer, electronic, clinical";
};
};
rx = true;
serialNumber = false;
singleUse = false;
sterilization = {
deviceSterile = false;
methodTypes = "<null>";
sterilizationPriorToUse = false;
};
versionModelNumber = 303000;
};

}

我需要提取“brandName”、“companyName”、“versionModelName”等关键元素。我很难找到正确的语法来从 JSON 字典中提取数据元素。

                        Alamofire.request(criteria).validate().responseJSON { responseJSON in
print(responseJSON.request) // original URL request
print(responseJSON.response) // HTTP URL response
print(responseJSON.data) // server data
print(responseJSON.result) // result of response serialization

if((responseJSON.value) != nil) {
if let json = responseJSON.result.value as? [String:Any]{
print(json)
let dataArray = json["gudid"] as? [[String:Any]]
print("JSON: \(dataArray)") // serialized json response

}


}

}

每当我引用 json["gudid"] 时都会收到错误。

有什么例子或建议吗?

最佳答案

我相信您的 json 格式错误,因此您无法解析它。请在这里测试一下: https://jsonlint.com/

编辑:

我认为它格式错误的原因是您必须将所有等号 (=) 替换为冒号 (:)。这是标准的 json 格式。

关于swift - Alamofire 之后解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44725771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com