开发者

Difference between these two requests

Request One (Not working)

{
    "AddNewRequest":{
        "Patient":{
            "PrimaryPhoneNumber":" ",
            "DateOfBirth":" ",
            "CellPhoneNumber1":" ",
            "ResidentialAddress":{
                "AddressLine1":" ",
                "State":" ",
                "City":" ",
                "PostalCode":" "
            },
            "PhoneNumber1":" ",
            "SSN":" ",
            "FullName":开发者_Python百科"John",
            "Religion":" ",
            "Gender":" ",
            "Race":" ",
            "Firstname":"Vinoth",
            "EmailAddress1":" ",
            "LastName":"Cooper"
        },
        "Header":{
            "SourceSiteID":"300242",
            "DestinationSiteID":"300242",
            "PrimeSuiteUserID":"1"
        },
        "Credentials":{
            "VendorCredential":{
                "VendorLogin":"testGUID",
                "VendorPassword":"testGUID"
            },
            "PrimeSuiteCredential":{
                "PrimeSuiteUserPassword":"password",
                "PrimeSuiteSiteId":"1",
                "PrimeSuiteUserName":"Admin"
            }
        }
    }
}

Request Two (Working)

{
    "PatientAddNewRequest":{
        "Credentials":{
            "PrimeSuiteCredential":{
                "PrimeSuiteSiteId":"300242",
                "PrimeSuiteUserName":"Admin",
                "PrimeSuiteUserPassword":"password"
            },
            "VendorCredential":{
                "VendorLogin":"testGUID",
                "VendorPassword":"testGUID"
            }
        },
        "Header":{
            "DestinationSiteID":"300242",
            "PrimeSuiteUserID":"1",
            ":SourceSiteID":"300242"
        },
        "Patient":{
            "CellPhoneNumber1":"206-567-2222",
            "DateOfBirth":"/Date(1306348200000)/",
            "EmailAddress1":"JohnDoe@yahoo.com",
            "Firstname":"TestMan1",
            "FullName":"TestFullMan1",
            "Gender":"2",
            "LastName":"Testlastname1",
            "PhoneNumber1":"205-567-1111",
            "PrimaryPhoneNumber":"205-456-4545",
            "Race":"2",
            "Religion":"3",
            "ResidentialAddress":{
                "City":"Carrollton",
                "PostalCode":"35209",
                "State":"10"
            },
            "SSN":"911-91-9191"
        }
    }
}

I am just not able to figure out why the first request is not working and the second one gives response. Can anyone identify what i am doing wrong.

Does Order Matter?

Update

The First one throws me Bad Request and the second one responds as expected.


In JSON the order doesn't matter but the name does. In the Request One you have "AddNewRequest" while in Request Two you have "PatientAddNewRequest".

Also on the server side, the serializer/de-serializer may need specific ordering.

JSON

An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.


We do not know your code that is processing these "requests", but to answer your question:

Yes, order of elements in JSON can matter

...unless your code processes it in a way that is not influenced by the order of them.

For example, if you have two objects:

  1. {prop1: 'abc', prop2: 'xyz'}
  2. {prop2: 'xyz', prop1: 'abc'}

and you process them in the following way in PHP for example:

$data = json_decode($request_string);
foreach ($data as $key => $value) {
    echo '['.$value.']';
}

you should receive following results:

  1. for the first request: [abc][xyz]
  2. for the second request: [xyz][abc]

but if you do it like that:

$data = json_decode($request_string);
echo '['.$data['prop1'].']['.$data['prop1'].']';

you will receive same result in both cases, that is:

[abc][xyz]

Hope that clarifies something.


Rename property name in #1 request

Have you tried renaming AddNewRequest to PatientAddNewRequest in the first request? Any difference?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜