Json 路径不正常

Json Path is not working fine

我有 json 消息,我必须从中检索两个不同的值。我使用 json 路径,但它没有检索到任何响应。以下是 json 消息。

{
    "ContractAgreements": {
        "ContractAgreement": [
            {
                "Code": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": null
            },
            {
                "Code": 123,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": {
                        "Code": "abc",
                        "ContractedOneOffCharges": {
                            "ContractedOneOffCharge": {
                                "ContractAgreementCode": 123,
                                "Charge": {
                                    "Code": "tekenbonus",
                                    "LanguageDescriptions": {
                                        "LanguageDescription": [
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": "teken bonus"
                                            },
                                            {
                                                "Description": "Signing Fee"
                                            }
                                        ]
                                    }
                                },
                                "OneOffChargeCode": "START",
                                "Status": "INACTIVE",
                                "Criteria1": null,
                                "Criteria2": null,
                                "Criteria3": null,
                                "AmountWithoutTax": null,
                                "OperationDate": null
                            }
                        },
                        "ContractedCharges": null,
                        "ContractedUsageCharges": null,
                        "TerminationReasonCode": null
                    }
                }
            },
            {
                "Code": 1234567,
                "LocationCode": 123,
                "Description": "test",
                "PackageCode": "abc",
                "StartDate": "2015-05-02T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "DirectDebet",
                            "ContractAgreementCode": 123,
                            "Status": "TERMINATED",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc Contract",
                            "ContractAgreementCode": 1234567,
                            "Status": "INACTIVE",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            },
            {
                "Code": "abc",
                "LocationCode": 123,
                "Description": "abc",
                "PackageCode": "abc",
                "StartDate": "2015-04-23T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": 871687940005297500,
                    "StartDate": "2015-04-23T00:00:00Z"
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "No",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-28T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": {
                                "ContractedUsageCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "Elektra High",
                                        "Description": "xyz",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Hoog"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "TERMINATED",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "AmountWithoutTax": null,
                                    "CounterCode": "abc1"
                                }
                            },
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "INACTIVE",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": {
                                "ContractedRecurringCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "abc",
                                        "Description": "abc",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Capaciteits Tarief"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "xyz"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "INACTIVE",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "StartDate": 1429747200000,
                                    "AmountWithoutTax": null,
                                    "OperationDate": "2015-04-23",
                                    "NextChargeDate": null
                                }
                            },
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            }
        ]
    }
}

我必须从中检索 "code":"Elektra High" 并且下面给出 json 路径。

ContractAgreements.ContractAgreement[2].Charge.Code

但是它没有检索到任何东西。 需要帮助。

试穿php

<?php
$datas = '{
    "ContractAgreements": {
        "ContractAgreement": [
            {
                "Code": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": null
            },
            {
                "Code": 123,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": {
                        "Code": "abc",
                        "ContractedOneOffCharges": {
                            "ContractedOneOffCharge": {
                                "ContractAgreementCode": 123,
                                "Charge": {
                                    "Code": "tekenbonus",
                                    "LanguageDescriptions": {
                                        "LanguageDescription": [
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": "teken bonus"
                                            },
                                            {
                                                "Description": "Signing Fee"
                                            }
                                        ]
                                    }
                                },
                                "OneOffChargeCode": "START",
                                "Status": "INACTIVE",
                                "Criteria1": null,
                                "Criteria2": null,
                                "Criteria3": null,
                                "AmountWithoutTax": null,
                                "OperationDate": null
                            }
                        },
                        "ContractedCharges": null,
                        "ContractedUsageCharges": null,
                        "TerminationReasonCode": null
                    }
                }
            },
            {
                "Code": 1234567,
                "LocationCode": 123,
                "Description": "test",
                "PackageCode": "abc",
                "StartDate": "2015-05-02T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "DirectDebet",
                            "ContractAgreementCode": 123,
                            "Status": "TERMINATED",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc Contract",
                            "ContractAgreementCode": 1234567,
                            "Status": "INACTIVE",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            },
            {
                "Code": "abc",
                "LocationCode": 123,
                "Description": "abc",
                "PackageCode": "abc",
                "StartDate": "2015-04-23T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": 871687940005297500,
                    "StartDate": "2015-04-23T00:00:00Z"
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "No",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-28T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": {
                                "ContractedUsageCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "Elektra High",
                                        "Description": "xyz",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Hoog"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "TERMINATED",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "AmountWithoutTax": null,
                                    "CounterCode": "abc1"
                                }
                            },
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "INACTIVE",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": {
                                "ContractedRecurringCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "abc",
                                        "Description": "abc",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Capaciteits Tarief"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "xyz"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "INACTIVE",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "StartDate": 1429747200000,
                                    "AmountWithoutTax": null,
                                    "OperationDate": "2015-04-23",
                                    "NextChargeDate": null
                                }
                            },
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            }
        ]
    }
}';
$datas = json_decode($datas);
echo '<pre>';
print_r($datas->ContractAgreements->ContractAgreement[3]->ContractedProducts->ContractedProduct[2]->ContractedUsageCharges->ContractedUsageCharge->Charge->Code);

js上应该是这个

data.ContractAgreements.ContractAgreement[3].ContractedProducts.ContractedProduct[2].ContractedUsageCharges.ContractedUsageCharge.Charge.Code

结果是"Elektra High"