Why won't Appcelerator Titanium Mobile parse this JSON? - ajax

Using 1.4.1 against Android under Windows 7. I have a web service being access from the Titanium application, the service returns JSON like this:
{
"VFPData": {
"rows": [
{
"address1": "Orion House",
"address2": "Orion Way",
"address3": "Kettering",
"address4": "Northants",
"comp_name": "Orion Vehicles Leasing",
"contid": 1,
"email": "",
"email2": "",
"fax": "",
"firstname": "David John",
"lastname": "Sear",
"mobile": "",
"phone1": "",
"phone2": "",
"postcode": "NN15 6PE"
},
{
"address1": "Unit 20 Acton Business Park",
"address2": "Acton Lane",
"address3": "London",
"address4": "",
"comp_name": "Orion Vehicles Limited",
"contid": 2,
"email": "Mark#ovl.co.uk",
"email2": "",
"fax": "",
"firstname": "Mark",
"lastname": "Johnson",
"mobile": "0888 566 67879",
"phone1": "0208 209 1359",
"phone2": "",
"postcode": "NW10 7NH"
}
]
}
}
However no combination of eval or JSON.parse will return a valid result - for example:
var contacts = JSON.parse(this.responseText);
alert(contacts.length);
That will show an alert dialog with nothing in it. The Titanium HTTPClient calls are working fine as I can
Ti.debug(this.responseText)
with no problem.
That JSON validates OK as well, in jsonlint.com for example.

The JSON looks fine, and parses fine... but is the line:
alert(contacts.length);
the only part that leads you to believe it isn't working? Because you can't get the length of an object (VFPData)... you'll get undefined/null whether valid parsing happened or not. A better test is:
alert(contacts.VFPData.rows.length);
... since you know rows is an array. Or:
alert(contacts);
Which should report it's an object (if parsed) or null/undefined otherwise.

Related

Nifi - Route the JSON based on the Array Name

I am new to Nifi, i hv a requirement where we get multiple JSON inputs with different Header Names. I have to parse the JSON and insert into different tables based on the Header value.
Not sure how to use RouteonContent processor or EvaluateJSON Path processor
Input 1
{
"Location": [
{
"country": "US",
"division": "Central",
"region": "Big South",
"locationID": 1015,
"location_name": "Hattiesburg, MS (XF)",
"location_type": "RETAIL",
"location_sub_type": "COS",
"store_type": "",
"planned_open_date": "",
"planned_close_date": "",
"actual_open_date": "2017-07-26",
"actual_close_date": "",
"new_store_flag": "",
"address1": "2100 Lincoln Road",
"address2": "",
"city": "Hattiesburg",
"state": "MS",
"zip": 39402,
"include_for_planning": "Y"
},
{
"country": "US",
"division": "Central",
"region": "Big South",
"locationID": 1028,
"location_name": "Laurel, MS",
"location_type": "RETAIL",
"location_sub_type": "COS",
"store_type": "",
"planned_open_date": "",
"planned_close_date": "",
"actual_open_date": "",
"actual_close_date": "",
"new_store_flag": "",
"address1": "1225 5th street",
"address2": "",
"city": "Laurel",
"state": "MS",
"zip": 39440,
"include_for_planning": "Y"
}
]
Input 2
{
"Item": [
{
"npi_code": "NEW",
"cifa_category": "XM",
"o9_category": "Accessories"
},
{
"npi_code": "NEW",
"cifa_category": "XM0",
"o9_category": "Accessories"
}
]
Use the website https://jsonpath.com/ to figure out the proper JSON expression. But what you could potentially do is use: if the array contains either $.npi_code then do X and if it contains $. country, then do Y

API Platform 3 does not return null data in response body

In API Platform 2.7 the response body contained fields that had a null value, after upgrading to API Platform 3 the response body does not contain fields that have a null value. Is this deliberate or due to a configuration change I need to make.
I executed the same call from the api/docs page for 2.7 and 3.0 I expected the results to be the same.
API Platform 2.7 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"email": null,
"title": null,
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"suffix": null,
"photoMedia": null,
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"addressLineTwo": null,
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
"mobileNumber": null,
"workNumber": null
}
API Platform 3.0 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
}
Relates to this question
You only need to set skip_null_values to false in your normalization_context, because starting 3.0.0 beta 1 they decided it would become true by default.
If you need it to be false for all resources, you can set the default in your config/packages/api_platform.yaml:
api_platform:
...
defaults:
normalization_context:
skip_null_values: false

Validation of each field in JSON response using karate API

I want to validate particular fields in the response whether it is integer or float(ex: fullbathrooms field). I tried below code but getting match failed error. Could you please help here ?.....Thanks
Given path '/property-client'
And request {"address": <address>,"city": <city>,"state": <state>,"zipCode": <zipCode>}
When method post
Then status 200
And print response
And match response == {fullbathrooms:'#number'}
Examples:
|read('testFile1.csv')|
Error : match failed: EQUALS
Actual response:
{
"success": true,
"message": {
"version": "1.0",
"response": {
"id": "94568859",
"type": "express",
"responseheader": null,
"reportdata": {
"property": {
"source": null,
"type": null,
"dom": null,
"propertytype": "Single Family Residence",
"standardtype": null,
"address": {
"documentid": null,
"number": "150",
"directional": null,
"street": "BRIDGE",
"suffix": "RD",
"postdirectional": null,
"unit": "",
"city": "HILLSBOROUGH",
"state": "CA",
"zip": "94010",
"zipplus4": "6908",
"fulladdress": "150 BRIDGE RD, HILLSBOROUGH, CA 94010"
},
"info": {
"type": null,
"fips": "6081",
"county": "San Mateo",
"bedrooms": "5",
"bathrooms": "6.50",
"fullbathrooms": "6.50",
"totalrooms": "0",
"livingarea": "7750",
"totallivingarea": "7750",
"landarea": "41382",
"landareatype": null,
"pool": "true",
"landvalue": "6904800",
"improvementvalue": "3284414",
"assessedvalue": "10189214",
"assessedyear": "2021",
"taxvalue": "11746898",
"taxyear": "2021",
"deliquentyear": null,
"yearbuilt": "2011",
"propertytax": null,
"approxage": "11",
"parcelnumber": "032-400-110",
"titlecompany": null,
"geocode": {
"latitude": "37.563272",
"longitude": "-122.334442",
"geoqualitycode": ""
}
}
Please take some time to read the documentation: https://github.com/karatelabs/karate#match-contains
I'm not going to refer to your response dump (which by the way is not valid JSON), but give you a simple example. Please pay attention to the structure of your JSON. And note that the 6.50 is a string not a number in your response.
* def response = { "foo": { "bar": { "fullbathrooms": "6.50" } } }
* match response.foo.bar == { fullbathrooms: '#string' }
If you want to validate numbers within strings, please refer other answers, for example: https://stackoverflow.com/search?q=%5Bkarate%5D+number+regex

No ChannelData except message text while receiving incoming message from Skype in Bot Framework

When I'm receiving the message from Telegram, I get detailed information about account in Activity.ChannelData field (such as username, conversation_id and so on).
{
"update_id": ,
"callback_query": {
"id": "",
"from": {
"id": ,
"is_bot": false,
"first_name": "",
"last_name": "",
"username": "",
"language_code": ""
},
"message": {
"message_id": ,
"from": {
"id": ,
"is_bot": true,
"first_name": "",
"username": ""
},
"chat": {
"id": ,
"first_name": "",
"last_name": "",
"username": "",
"type": "private"
},
"date": ,
"text": "Example text"
},
"chat_instance": "",
"data": ""
}
}
But when it comes to Skype, all I see is the message text and nothing else.
{ "text": "Example text"}
How to know out, who exatly sent me the message?
Upd: That should not be exactly the user's name, any additional data like user unique id would fit.
Unfortunately, what is returned is channel specific, as determined by the channel developers. It is not a function of the Azure Bot Service or Bot Framework that determines this.
As for knowing who sent a message, this is not possible. Skype only returns a unique id per user in order to provide a layer of confidentiality with respect to privacy concerns.

How to bind image from json to xaml in windows phone

I am new to windows phone development. I'm working on an app that fetches json from webservice and parse it using json.net to display data in windows phone. here's the sample json.
[
{
"id": "001",
"title": "title1",
"content": "sample content",
"category_id": "3",
"image": "defaultimg.jpg"
},
{
"id": "021",
"title": "title2",
"content": "sample content",
"category_id": "1",
"image": "defaultimg2.jpg"
},
{
"id": "011",
"title": "title3",
"content": "sample content",
"category_id": "3",
"image": "defaultimg22.jpg"
},
]
is it possible to bind the image with that kind of format? or it should be in url format?
Instead of passing then image path, pass a base64 encoded image string and then use that in the view.

Resources