【问题标题】:ErrorException (E_ERROR) Undefined index: streetNumber [duplicate]ErrorException (E_ERROR) 未定义索引:streetNumber [重复]
【发布时间】:2018-04-02 13:17:10
【问题描述】:

我有这个解码的 JSON,想在我的视图中显示数据,但我得到了

错误异常 (E_ERROR) 未定义索引:streetNumber

以下是数据示例:

array(11) {
    [0] => array(26) {
        ["privateRemarks"] => string(98)
        "Please use showing time and *** is available for any questions regarding showings at 00000" ["property"] => array(40) {
            ["roof"] => NULL["cooling"] => string(27)
            "Central Cooling,Paddle Fans" ["style"] => string(8)
            "Detached" ["area"] => NULL["bathsFull"] => int(5)["bathsHalf"] => int(1)["stories"] => NULL["fireplaces"] => NULL["flooring"] => string(13)
            "Marble Floors" ["heating"] => string(26)
            "Central Heat,Electric Heat" ["bathrooms"] => string(4)
            "6.00" ["foundation"] => NULL["laundryFeatures"] => NULL["occupantName"] => NULL["ownerName"] => NULL["lotDescription"] => string(22)
            "Less Than 1/4 Acre Lot" ["pool"] => string(17)
            "Below Ground Pool" ["subType"] => NULL["bedrooms"] => int(5)["interiorFeatures"] => string(18)
            "Second Floor Entry" ["lotSize"] => string(6)
            "55x127" ["areaSource"] => NULL["maintenanceExpense"] => NULL["additionalRooms"] => string(38)
            "Family Room,Other,Utility Room/Laundry" ["exteriorFeatures"] => string(35)
            "High Impact Doors,Exterior Lighting" ["water"] => string(15)
            "Municipal Water" ["view"] => string(25)
            "Ocean View,Pool Area View" ["lotSizeArea"] => int(55)["subdivision"] => NULL["construction"] => string(16)
            "CBS Construction" ["parking"] => array(3) {
                ["leased"] => NULL["spaces"] => NULL["description"] => string(8)
                "Driveway"
            }["lotSizeAreaUnits"] => NULL["type"] => string(3)
            "RES" ["garageSpaces"] => int(2)["bathsThreeQuarter"] => NULL["accessibility"] => NULL["acres"] => NULL["occupantType"] => string(18)
            "Call Listing Agent" ["subTypeText"] => NULL["yearBuilt"] => int(2006)
        }["mlsId"] => int(000000)["terms"] => NULL["showingInstructions"] => NULL["office"] => array(4) {
            ["contact"] => array(3) {
                ["email"] => NULL["office"] => string(12)
                "000000000" ["cell"] => NULL
            }["name"] => string(15)
            "**********" ["servingName"] => string(15)
            "**********" ["brokerid"] => string(6)
            "*****"
        }["leaseTerm"] => NULL["disclaimer"] => string(66)
        "This information is believed to be accurate, but without warranty." ["address"] => array(10) {
            ["crossStreet"] => NULL["state"] => string(2)
            "FL" ["country"] => string(13)
            "United States" ["postalCode"] => string(5)
            "33304" ["streetName"] => string(28)
            "N Fort Lauderdale Beach Blvd" ["streetNumberText"] => string(4)
            "00000" ["city"] => string(15)
            "Fort Lauderdale" ["streetNumber"] => int(0000)["full"] => string(33)
            "******* Beach Blvd" ["unit"] => NULL
        }["agreement"] => string(28)
        "Exclusive Right to Sell/Rent" ["listDate"] => NULL["agent"] => array(4) {
            ["lastName"] => string(8)
            "******" ["contact"] => array(3) {
                ["email"] => string(16)
                "***********" ["office"] => string(12)
                "******" ["cell"] => NULL
            }["firstName"] => string(6)
            "*****" ["id"] => string(7)
            "******"
        }["modified"] => string(24)
        "2018-04-01T08:27:17.903Z" ["school"] => NULL["photos"] => array(65) {
            [0] => string(168)
            "img.jpg" [1] => string(168)

        }["listPrice"] => int(00005000)["listingId"] => string(9)
        "*******" ["mls"] => array(6) {
            ["status"] => string(6)
            "Active" ["area"] => string(4)
            "3160" ["daysOnMarket"] => NULL["originatingSystemName"] => NULL["statusText"] => string(6)
            "Active" ["areaMinor"] => NULL
        }["geo"] => array(5) {
            ["county"] => string(14)
            "Broward County" ["lat"] => NULL["lng"] => NULL["marketArea"] => string(4)
            "31" ["directions"] => NULL
        }["tax"] => array(3) {
            ["taxYear"] => int(2017)["taxAnnualAmount"] => int(41)["id"] => string(12)
            "494331"
        }["coAgent"] => NULL["sales"] => NULL["leaseType"] => NULL["virtualTourUrl"] => string(56)
        "https://www.prop.com" ["remarks"] => string(65)
        "4 levels of your estate." ["association"] => array(3) {
            ["fee"] => int(0)["name"] => string(10)
            "Homeowners" ["amenities"] => NULL
        }

    }
}

这里是控制器摘录

$properties = json_decode($file, true);
return view('properties.all-properties')->with('properties',$properties);

这是我认为的测试

@foreach($properties as $details) 
    {{ $details["streetNumber"] }}
@endforeach

我想循环遍历数据并构建列表信息

【问题讨论】:

  • 查看streetNumber 在您的阵列中的位置。它不在顶层。
  • 当你的数组被这样格式化时,很难看到它的样子。
  • 在这个示例中,我只在 ["privateRemarks"] 之后显示了一个列表 ["property"],json 显示了 26 个列表,你们可以显示一些示例代码或指出一个好的关于循环 JSON 数组的教程?

标签: php arrays json laravel-5


【解决方案1】:

streetNumberaddress 内。 所以理想情况下应该是

@foreach($properties as $details) 
    {{ $details["address"]["streetNumber"] }}
@endforeach

将来,如果您遇到此类问题,您的第一步是打印$details 并查看其中的内容。

Stackoverflow 适用于一般问题和解决方案。您还可以在 google 上复制粘贴错误并了解该错误出现的原因。

【讨论】:

    猜你喜欢
    • 2018-11-29
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    相关资源
    最近更新 更多