-2

こんにちは、以下のようなエラーが発生する JSON 形式の URL を解析しています

JSONValue failed. Error trace is: (
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=5 \"Unescaped control character '0xa'\" UserInfo=0x1d224220 {NSLocalizedDescription=Unescaped control character '0xa'}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: Location\" UserInfo=0x1d2242d0 {NSUnderlyingError=0x1d224260 \"Unescaped control character '0xa'\", NSLocalizedDescription=Object value expected for key: Location}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Expected value while parsing array\" UserInfo=0x1d224310 {NSUnderlyingError=0x1d2242f0 \"Object value expected for key: Location\", NSLocalizedDescription=Expected value while parsing array}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: GetIssues\" UserInfo=0x1d224350 {NSUnderlyingError=0x1d224330 \"Expected value while parsing array\", NSLocalizedDescription=Object value expected for key: GetIssues}"

しかし、ブラウザで同じ URL にアクセスすると、完全に機能します。どこが間違っているのか教えてください。

私のjson出力は

{"GetIssues": [{ "PhotoUrl" : "http://city311.smartletmanager.com/city311/uploads/Sideways_SWS_122_154.jpg", "IssueName" : "Sidewalk Construction Permit", "Comments" : "N/A", "Location" : "Rajiv Gandhi Salai Tamil Nadu India", "Status" : "Not Fixed", "issueSubmittedDate" : "2012-12-28 12:40:20" },{ "PhotoUrl" : "http://city311.smartletmanager.com/city311/uploads/Environment_ENV_123_287.jpg", "IssueName" : "Dust Complaint", "Comments" : "N/A", "Location" : "Rajiv Gandhi Salai Tamil Nadu India", "Status" : "Not Fixed", "issueSubmittedDate" : "2012-12-28 12:52:35" },{ "PhotoUrl" : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_124_342.jpg", "IssueName" : "Resources for passengers with disabilities and taxi drivers", "Comments" : "Tug", "Location" : "Ggj", "Status" : "Fixed", "issueSubmittedDate" : "2012-12-28 14:14:56" }]}

json 値を取得する前に文字列を出力しようとすると。出力をjsonとして取得しました:

{"GetIssues":
            [{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Sideways_SWS_122_154.jpg",
                "IssueName"     : "Sidewalk Construction Permit",
                "Comments"      : "N/A",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-28 12:40:20"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Environment_ENV_123_287.jpg",
                "IssueName"     : "Dust Complaint",
                "Comments"      : "N/A",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-28 12:52:35"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_124_342.jpg",
                "IssueName"     : "Resources for passengers with disabilities and taxi drivers",
                "Comments"      : "Tug",
                "Location"          : "Ggj",
                "Status"            : "Fixed",
                "issueSubmittedDate"    : "2012-12-28 14:14:56"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_125_620.jpg",
                "IssueName"     : "Resources for passengers with disabilities and taxi drivers",
                "Comments"      : "Ryffhdugdjstiin",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:17:18"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Sideways_SWS_126_736.jpg",
                "IssueName"     : "Sidewalk Construction Permit",
                "Comments"      : "Drrtg",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:18:26"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_127_84.jpg",
                "IssueName"     : "Blocked Sidewalk or Street Complaint",
                "Comments"      : "Erttyyyy",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:19:04"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_128_642.jpg",
                "IssueName"     : "Sidewalk Repair Protest",
                "Comments"      : "Qwerty",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:19:35"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_129_359.jpg",
                "IssueName"     : "Resources for passengers with disabilities and taxi drivers",
                "Comments"      : "Werttyy",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:20:18"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_130_914.jpg",
                "IssueName"     : "Snow or Ice on Roadway/Sidewalks",
                "Comments"      : "Rtyygguhh",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:20:50"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_131_983.jpg",
                "IssueName"     : "Pedestrian Signal with Walk and Don’t Walk Displaying.",
                "Comments"      : "Rt",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:21:23"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_132_11.jpg",
                "IssueName"     : "Dirty yard or alley complaints",
                "Comments"      : "Truth",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:21:54"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_133_33.jpg",
                "IssueName"     : "Improper Disposal",
                "Comments"      : "Ttyyu",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:22:23"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_134_40.jpg",
                "IssueName"     : "Snow or Ice on Roadway/Sidewalks",
                "Comments"      : "Ytterbium",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:22:56"
           },{ "PhotoUrl"       : "http://city311.smartletmanager.com/city311/uploads/Transport_TRP_135_689.jpg",
                "IssueName"     : "Illegal Parking",
                "Comments"      : "N/A",
                "Location"          : "Rajiv Gandhi Salai
Tamil Nadu
India",
                "Status"            : "Not Fixed",
                "issueSubmittedDate"    : "2012-12-31 00:31:17"
           }]}

でもあげた後は

NSArray *issueDetailsAry = [json JSONValue];
//objectForKey:@"GetIssues"];
     NSLog(@"issueDetailsAry %@",issueDetailsAry);

私は次のように出力を得ました

-JSONValue failed. Error trace is: (
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=5 \"Unescaped control character '0xa'\" UserInfo=0x8356b20 {NSLocalizedDescription=Unescaped control character '0xa'}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: Location\" UserInfo=0x8357850 {NSUnderlyingError=0x8356b70 \"Unescaped control character '0xa'\", NSLocalizedDescription=Object value expected for key: Location}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Expected value while parsing array\" UserInfo=0x83578a0 {NSUnderlyingError=0x8356a90 \"Object value expected for key: Location\", NSLocalizedDescription=Expected value while parsing array}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: GetIssues\" UserInfo=0x8357930 {NSUnderlyingError=0x83578f0 \"Expected value while parsing array\", NSLo
4

1 に答える 1

3

/n をjson文字列の空の文字列に置き換えることで、この問題を修正しました

NSString *json = [[NSString alloc]init];

json = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
json = [json stringByReplacingOccurrencesOfString:@"\n" withString:@""];

// NSLog(@"json %@",json); NSArray *issueDetailsAry = [[json JSONValue]objectForKey:@"GetIssues"];

今、私は出力を得ました。この問題は、サーバー側の改行が原因です。

于 2012-12-31T08:19:19.157 に答える