json数据格式不正确

时间:2018-11-16 10:38:34

标签: ios json swift

我正在调用搜索的api,当我单击搜索按钮时,我得到了正确的响应,然后当我重定向到第二个VC时,我进入了下一个viewcontroller,我得到了类似以下的错误

Error: The data couldn’t be read because it isn’t in the correct format.

现在,我将向您展示我在点击搜索按钮时得到的答复

回复:

{
    news =     (
                {
            "A_ADDRESS" = "A/304, GARDEN VIEW
\nKULUPWADI ROAD
\nBORIVALI EAST
\n";
            "A_BLOOD_GROUP" = 7;
            "A_CITY" = 819;
            "A_CURRENT_ACTIVITY" = 7;
            "A_DOB" = "{\"D\":\"20\",\"M\":\"January\",\"Y\":\"1938\"}";
            "A_EMAIL" = "HIMATPATEL@HOTMAIL.COM";
            "A_FAMILY_ID" = 000257;
            "A_FATHER_NAME" = RAMJI;
            "A_FULLNAME" = BHIMJI;
            "A_ID" = 422;
            "A_IMG" = "";
            "A_MERITAL_STATUS" = 4;
            "A_NATIVE_ADDRESS" = "Virani Nani
\nNear Gadhshisha
\nTal : Mandvi
\nDist : Kutch Bhuj";
            "A_N_CITY" = 2388;
            "A_N_STATE" = 14;
            "A_N_city" = "Virani Nani";
            "A_PHONE" = 9820995150;
            "A_ROLE" = f;
            "A_STATE" = 23;
            "A_SURNAME" = 1;
            age = "";
            city = Mumbai;
            education = "STD: 4TH";
        },
                {
            "A_ADDRESS" = "B/181, Bhavaninagar,
\nNear Military Camp,
\nGalpadar,";
            "A_BLOOD_GROUP" = 9;
            "A_CITY" = 2395;
            "A_CURRENT_ACTIVITY" = 1;
            "A_DOB" = "{\"D\":\"1\",\"M\":\"November\",\"Y\":\"1966\"}";
            "A_EMAIL" = "ROHITBPATEL33@GMAIL.COM";
            "A_FAMILY_ID" = 000264;
            "A_FATHER_NAME" = MAVJIBHAI;
            "A_FULLNAME" = BHIMJI;
            "A_ID" = 429;
            "A_IMG" = "";
            "A_MERITAL_STATUS" = 2;
            "A_NATIVE_ADDRESS" = "";
            "A_N_CITY" = 2346;
            "A_N_STATE" = 14;
            "A_N_city" = Nakhatrana;
            "A_PHONE" = 9723894800;
            "A_ROLE" = f;
            "A_STATE" = 14;
            "A_SURNAME" = 1;
            age = "";
            city = Gandhidham;
            education = 10TH;
        },
                {
            "A_ADDRESS" = TARAPUR;
            "A_BLOOD_GROUP" = 3;
            "A_CITY" = 394;
            "A_CURRENT_ACTIVITY" = 4;
            "A_DOB" = "{\"D\":\"1\",\"M\":\"January\",\"Y\":\"1958\"}";
            "A_EMAIL" = "";
            "A_FAMILY_ID" = 000626;
            "A_FATHER_NAME" = JETHA;
            "A_FULLNAME" = BHIMJI;
            "A_ID" = 805;
            "A_IMG" = "";
            "A_MERITAL_STATUS" = 2;
            "A_NATIVE_ADDRESS" = "";
            "A_N_CITY" = 2328;
            "A_N_STATE" = 14;
            "A_N_city" = "Kotda Jadodar";
            "A_PHONE" = 9099849216;
            "A_ROLE" = f;
            "A_STATE" = 14;
            "A_SURNAME" = 2;
            age = "";
            city = Talaja;
            education = OTHER;
        },
                {
            "A_ADDRESS" = "1014/4/4 11 TH MAIN HAMPI NAGAR RPC LAYOUT VIJAYNAGAR ";
            "A_BLOOD_GROUP" = 9;
            "A_CITY" = 546;
            "A_CURRENT_ACTIVITY" = 1;
            "A_DOB" = "";
            "A_EMAIL" = "";
            "A_FAMILY_ID" = 001019;
            "A_FATHER_NAME" = DHANJI;
            "A_FULLNAME" = BHIMJI;
            "A_ID" = 1200;
            "A_IMG" = "";
            "A_MERITAL_STATUS" = 2;
            "A_NATIVE_ADDRESS" = "KOTADA JADODAR (NAVAVAS)
\nNAKHATRANA";
            "A_N_CITY" = 2328;
            "A_N_STATE" = 14;
            "A_N_city" = "Kotda Jadodar";
            "A_PHONE" = 9448113867;
            "A_ROLE" = f;
            "A_STATE" = 19;
            "A_SURNAME" = 2;
            age = 0;
            city = Bangalore;
            education = 10TH;
        },
                {
            "A_ADDRESS" = "PLOT NO:- 10, MAHADEV NAGAR-3,
\nNEAR SUN CITY,
\nSVCT MUNDRA ROAD,";
            "A_BLOOD_GROUP" = 9;
            "A_CITY" = 2394;
            "A_CURRENT_ACTIVITY" = 4;
            "A_DOB" = "{\"D\":\"1\",\"M\":\"January\",\"Y\":\"1937\"}";
            "A_EMAIL" = "";
            "A_FAMILY_ID" = 000413;
            "A_FATHER_NAME" = HARJI;
            "A_FULLNAME" = BHIMJI;
            "A_ID" = 2005;
            "A_IMG" = "M_566d65b562e55.jpg";
            "A_MERITAL_STATUS" = 2;
            "A_NATIVE_ADDRESS" = "NEAR OLD POLISH STATION,
\nVAD FADIYU,
\nJUNAVAS,";
            "A_N_CITY" = 1966;
            "A_N_STATE" = 14;
            "A_N_city" = Mankuva;
            "A_PHONE" = "";
            "A_ROLE" = 22;
            "A_STATE" = 14;
            "A_SURNAME" = 2;
            age = "";
            city = Bhuj;
            education = 3RD;
        },
                {
            "A_ADDRESS" = "37 dev avenue behind mmpj hospital 
\nBhuj kutchh";
            "A_BLOOD_GROUP" = 9;
            "A_CITY" = 2394;
            "A_CURRENT_ACTIVITY" = 3;
            "A_DOB" = "{\"D\":\"29\",\"M\":\"December\",\"Y\":\"1945\"}";
            "A_EMAIL" = "";
            "A_FAMILY_ID" = 001175;
            "A_FATHER_NAME" = VISHRAM;
            "A_FULLNAME" = BHIMJI;
            "A_ID" = 6532;
            "A_IMG" = "";
            "A_MERITAL_STATUS" = 2;
            "A_NATIVE_ADDRESS" = "";
            "A_N_CITY" = 2388;
            "A_N_STATE" = 14;
            "A_N_city" = "Virani Nani";
            "A_PHONE" = "";
            "A_ROLE" = 22;
            "A_STATE" = 14;
            "A_SURNAME" = 1;
            age = "";
            city = Bhuj;
            education = 7TH;
        }
    );
}

这是我将检入json验证程序的响应,它还说json有效

现在,我将向您展示我用于搜索的代码

搜索代码

  func getAdvanceData() {
        let sURL = "http://velanivasaniparivar.org/jsonadvancesearch.php"
        let dataPost:String="A_FATHER_NAME="+sFatherName+"&A_FULLNAME="+sName+"&sur_name="+sSurname+"&membertype="+sMember+"&c_type="+sCityType+"&city="+sCity+"&A_STATE="+sState+"&education1="+sEducation+"&A_BLOOD_GROUP="+sBlood+"&A_FAMILY_ID="+sFamily+"&A_PHONE="+sMobile+"&business="+sOccupation

        print("Parameter",dataPost)


        getDataPostData(sURL: sURL, postData: dataPost, successHandler: {
            (response) in
            print("Result",self.getdataToString(data: response))
            self.strResult = self.getdataToString(data: response)
           //print(self.strResult)
            if let data = self.strResult.replacingOccurrences(of: "\n", with: "\\n").data(using: String.Encoding.utf8) {
                do {
                    let a = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
                    //NSLog("check \(a)")\
                    //print(a)
                    let rollNumber:String = String(format: "%@", a as! CVarArg)
                     print(rollNumber)
                    self.strResult1 = rollNumber
                } catch {
                    NSLog("ERROR \(error.localizedDescription)")
                }
            }

            DispatchQueue.main.async(execute: {
                if self.strResult1.range(of:"A_FAMILY_ID") != nil{
                    let VC = self.storyboard?.instantiateViewController(withIdentifier: "AdvanceSearchResultViewController") as! AdvanceSearchResultViewController
                    self.present(VC, animated: true, completion: nil)
                }else {
                    self.myAlert(t: "!oops No Data", msg: "Please fill proper information and try again.")
                }
            })
        })

    }

所以这是我得到正确响应的情况,但是当我重定向到下一个VC时,我没有格式化json错误,所以任何人都可以帮我解决这个问题

0 个答案:

没有答案