I'm trying to pass a list of integers (of the form [1,5]) as params in transitionTo in Ember 3.14. I've verified that the list can be read within this function:
afterModel() {
this.transitionTo('newRoute', this.modelFor('lastLevel').list);
},
But I always get this error:
Cannot read property '0' of undefined TypeError: Cannot read property '0' of undefined
How should I transform the list so it will pass into transitionTo()?
I found the pretty simple solution. I had to join the list into a string:
this.transitionTo('newRoute', this.modelFor('lastLevel').list.join(',');
Related
I get the response of a server:
r = requests.get(my_url)
print(r.text)
json_response = json.loads(r.text)
print(type(json_response))
I am using json.loads() to convert the string into json. However, the response has this format:
[{"element_info":{"data":201863539001,......]
I want to access element_info.data. I tried accessing it with json_response.element_info.data but i got AttributeError: 'list' object has no attribute 'bkdn_elem_info'.
I also tried content = r.read() and i got AttributeError: 'Response' object has no attribute 'read'.
You cannot access the elements of a dictionary in python with '.' operator as in javascript. You have to use the square bracket notation as below to access the elements
json_response[0]["element_info"]["data"]
The type of json_response is list. So, you can iterate on it and access each element in it. Each element is a dictionary. So, you can use the keys:
for each_element in json_response:
print(each_element["element_info"]["data"])
If you are not sure that these keys are available in all elements, you can use the get() method with a default value to avoid errors when the key does not exist. Here, the first operand is the key that you want to read, and the second operand can be used to define a default value:
for each_element in json_response:
print(each_element.get("element_info", {}).get("data", ""))
In access to data from a list, you must specify the element with index first and then get the property of the object
objectOfList =json_response[0];
value = objectOfList["element_info"]["data"];
I am struggling to select a property from a JSON array that I've stored in a variable (as an array). I receive the following error:
The execution of template action 'Select' failed: The evaluation of 'query' action >'where' expression '{
"Response": "#variables('UserEvents').responseStatus.response",
"trest": ""
}' failed: 'The template language expression >'variables('UserEvents').responseStatus.response' cannot be evaluated because property >'responseStatus' cannot be selected. Array elements can only be selected using an > integer index. Please see https://aka.ms/logicexpressions for usage details.'.
The JSON is below:
[
{
"value": [
{
"responseStatus": {
"response": "notResponded",
"time": "0001-01-01T00:00:00Z"
}
}
]
}
]
I'm trying to select the 'response' property only by using the following expression:
#variables('UserEvents').responseStatus.response
I have tried adding [0] to various parts of the above expression but it doesn't seem to make any difference. I am sure it's pretty simple and I'm just getting the syntax wrong, but am completely stuck!
Any help appreciated - thanks.
Adrian
#{
variables('UserEvents') ? ['value'] ? [0] ? ['response']
}
Try that. The integer index mentioned in the error is the way around this. May need to play around with the structure to make it match your data but [0] will make it select the first object within your value array.
There are 2 ways to get the properties inside a nested JSON
WAY - 1 (Try to get properties using For-each loop)
For this we need to use 2 for-each loops to retrieve the property inside the nested JSON After Parsing the JSON. Below is the screenshot of my logic app for your reference.
WAY - 2 (Using Dynamic Expression)
Here is the Expression that worked for me.
body('Parse_JSON')?[0]?['value']?[0]?['responseStatus']?['response']
Since it is in Array of Array format we need to mention the index of the array. Below is the screenshot of my logic app for your reference :
output :
In the following code, I want to concatenate the data in array arr1 with string value in variable t.
var t:String;
var arr4:Array = new Array();
for(w;w<i;w++){
if(max==arr3[w]){
t=t.concat(",",arr1[w])
}
}
trace(t);
But I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at final1_fla::MainTimeline/modebtn()
Can anyone help me?
That code doesn't make sense at all, arr4 is initialized but never used, instead arr3 and arr1 is used which might not be initialized and causing the null object reference error.
Your loop is using w which is not initialized and is comparing against i which isn't shown here.
Make sure your arrays are valid and check if that for loop is functioning as you expect it to.
I am working in yii framework.I am having json input as-
$json='{"userId":1,"questionPaperId":1;"optionId":2}';
So whilw creating functions in yii,i am decoding it and accessing these inputs as-
$obj=CJSON::decode($json);
$option=$obj->optionId;
$userId=$obj->userId;
$paperId=$obj->questionPaperId;
But its giving error as "Trying to get property of non-object ". So how to access this in yii?
You json string is syntax wrong.
$json='{"userId":1,"questionPaperId":1;"optionId":2}'; // note the ; in it
should be
$json='{"userId":1,"questionPaperId":1,"optionId":2}';
As CJSON::encode give you a json formatted string from an array, CJSON::decode return an array not an object.
So access it like that: $option=$obj["optionId"];
I came across this JSON code. I noticed that it makes use of undefined value. Where can I find more information about this value type?
tracks:[
( {
codec:"h264",
language:undefined,
id:1,
bitrate:785236,
content:"video"
} ),
( {
codec:"aac",
language:undefined,
id:2,
bitrate:75969,
content:"audio"
} )
],
undefined is not a valid JSON value, even though it is valid in javascript.
From the official JSON standard
(ECMA-404, Section 5):
A JSON value can be an object, array, number, string, true, false, or null.
For JSON, use null instead of undefined: { "something": null }
undefined is a special type where it simply indicates that the variable language is not initialized or may be it's not yet defined.
null in javascript simply indicates absence of a value, and it can also be used to indicate “no value” for numbers and strings as well as objects.The undefined value also represents absence of value, it is the value of the variables that have not been initialized and the value when you get from object property or array element that doesn’t exist
undefined is a predefined global variable that is initialized to undefined value.
null and undefined doesn’t have any properties or methods.In fact, using . or [] to access property or method of these values causes a TypeError.