从PHP中获取来自JSON数组的值(Get value from JSON array in PHP)
我试图从这个PHP变量中的下面的JSON数组中获取值。
这是一个数组的var_dump:
array(3) { ["id"]=> string(2) "14" ["css"]=> string(400) "" ["json"]=> string(4086) " { "Canvas": [ { "MainObjects": { "After Participation": { "afterParticipationHeader": "Thank you!" }, "Invite Friends": { "InviteHeadline": "", "InviteMsg": "", "InviteImg": "" } }, "QuizModule": { "Questions": [], "Submit_Fields": [ { "label": "Name", "name": "txtName", "value": true } ] } } ] }" }
我能够在PHP中获得[“json”]的值,如下所示:
$json = $data[0]['json'];
但是,如何从“json”内的数组中获取值,如“AfterParticipationHeader”。 和“Submit_Fields”?
I'm trying to get the value from this following JSON array in a PHP variable.
This is a var_dump of the array:
array(3) { ["id"]=> string(2) "14" ["css"]=> string(400) "" ["json"]=> string(4086) " { "Canvas": [ { "MainObjects": { "After Participation": { "afterParticipationHeader": "Thank you!" }, "Invite Friends": { "InviteHeadline": "", "InviteMsg": "", "InviteImg": "" } }, "QuizModule": { "Questions": [], "Submit_Fields": [ { "label": "Name", "name": "txtName", "value": true } ] } } ] }" }
I am able to get the values for ["json"] in PHP like:
$json = $data[0]['json'];
But how do I get the value from from the array inside "json", like "AfterParticipationHeader". And "Submit_Fields" ?
原文:https://stackoverflow.com/questions/17995877
最满意答案
我想我找到了你的问题:从
sm.add_constant
的文档中,你需要设置一个名为has_constant
的参数来设置add
(默认为skip
)。has_constant:str {'raise','add','skip'}如果``data''已经有一个常量的行为。 默认将返回数据而不添加另一个常量。 如果'raise',如果存在常量则会引发错误。 使用'add'将复制常量(如果存在)。 对结构化或重新排列没有影响。 在这种情况下,没有检查常数。
基本上对于循环的迭代,您的变量
time
在子集中是常量,因此函数没有添加常量,因此RollOLS.params只有2个条目。temp Out[12]: time X Y a b1 b2 541 0.16182 13 20.0 19.49 3.15289 -1.26116e-05 542 0.16182 14 20.0 20 0 7.10543e-15 543 0.16182 15 20.0 20 -7.45058e-09 0 sm.add_constant(temp.loc[:,['time','X']]) Out[13]: time X 541 0.16182 13 542 0.16182 14 543 0.16182 15 sm.add_constant(temp.loc[:,['time','X']], has_constant = 'add') Out[14]: const time X 541 1 0.16182 13 542 1 0.16182 14 543 1 0.16182 15
因此,如果你在
sm.add_constant
函数中有has_constant = 'add'
,那么错误就会消失,但是在解释变量中你会有两个线性相关的列,这使得矩阵不可逆,因此回归没有意义。I think I found your problem: from the documentation of
sm.add_constant
, there is an argument calledhas_constant
that you need to set toadd
(the default isskip
).has_constant : str {'raise', 'add', 'skip'} Behavior if ``data'' already has a constant. The default will return data without adding another constant. If 'raise', will raise an error if a constant is present. Using 'add' will duplicate the constant, if one is present. Has no effect for structured or recarrays. There is no checking for a constant in this case.
Essentially for that iteration of the loop your variable
time
was constant in the subset, hence the function did not add a constant and as a result RollOLS.params had only 2 entries.temp Out[12]: time X Y a b1 b2 541 0.16182 13 20.0 19.49 3.15289 -1.26116e-05 542 0.16182 14 20.0 20 0 7.10543e-15 543 0.16182 15 20.0 20 -7.45058e-09 0 sm.add_constant(temp.loc[:,['time','X']]) Out[13]: time X 541 0.16182 13 542 0.16182 14 543 0.16182 15 sm.add_constant(temp.loc[:,['time','X']], has_constant = 'add') Out[14]: const time X 541 1 0.16182 13 542 1 0.16182 14 543 1 0.16182 15
So the error is going away if you had
has_constant = 'add'
in thesm.add_constant
function, but you would have two linearly dependent columns in the explanatory variables, which makes the matrix not invertible hence the regression would not make sense.
相关问答
更多-
IndexError的原因是您使用变量名称i两次( for i in range(n) for i in range(rand-1,rand) )。 当调用x[i+1] ,我假设您期望外部for循环中的i ,但其值在内部意外更改。 尝试为另一个for循环使用不同的索引变量名称。 The reason for the IndexError is that you are using the variable name i twice (for i in range(n) and for i in range( ...
-
我想我找到了你的问题:从sm.add_constant的文档中,你需要设置一个名为has_constant的参数来设置add (默认为skip )。 has_constant:str {'raise','add','skip'}如果``data''已经有一个常量的行为。 默认将返回数据而不添加另一个常量。 如果'raise',如果存在常量则会引发错误。 使用'add'将复制常量(如果存在)。 对结构化或重新排列没有影响。 在这种情况下,没有检查常数。 基本上对于循环的迭代,您的变量time在子集中是常量,因 ...
-
IndexError:索引9超出了大小为9的轴0的界限(IndexError: index 9 is out of bounds for axis 0 with size 9)[2022-03-04]
您正在访问数组的边界之外。 在你的内循环中,你有一行binary = np.delete(binary, (loser), axis=0) 假设第一次通过,最小值的索引( loser )是9(10个元素数组的最后一个元素)。 您的binary数组长度为10.您从数组中删除该条目。 二进制数组现在长度为9. value数组中最小值的索引没有改变! 所以,下一次,当你试图通过print("binary:",(binary[loser,]))访问元素9时,你会得到一个错误。 至于解决你的问题,你正在使用从一个数组 ... -
IndexError:index超出了0轴python numpy的范围(IndexError: index is out of bounds for axis 0 python numpy)[2022-12-01]
你需要在N1而不是N上设置停止条件: while N1 < len(test): Your need to put stop condition on N1 instead of N: while N1 < len(test): -
至少其中一个room.x1 + 1 , room.x2 , room.y1 + 1和room.y2超出了你的地图。 检查地图大小或限制访问权限。 选项1: class RoomOutsideError(Exception): pass # ... def create_room(room): global map #set all tiles inside the room to passable # check for limits and raise excepti ...
-
您需要检查字符串的长度,例如: letterCount+2 <= len(s) 即 s = 'oobobodobooobobobobabobbobbobobbobbobhbxbobbk' vowelCount = 0 letterCount = 0 pointer = s for pointer in s: print(pointer) if pointer == 'b': print (str(letterCount) + '. betű B' ) ...
-
您的安装似乎有些问题 - 很难看出线路如何 while logger: 会生成一个IndexError 。 因此,从系统中删除所有.pyc和.pyo文件(包括在stdlib文件夹中),然后重试。 确保您的模块没有与标准库中的任何模块同名。 另外,您使用的是哪个版本的Python,以及在哪个平台上? 更新:如果您在C ++程序中使用嵌入式或使用C扩展,很可能某些C或C ++代码会破坏内存,从而导致IndexError在意外的地方。 你能在纯Python环境中重现吗? 如果没有,我担心问题可能出在C / C ...
-
你在range (0, len(chests))进行迭代range (0, len(chests)) ,然后在线路visits[i] += 1中得到错误。 看起来像chests和visits长度不等。 我看不到任何appends到visits列表,所以它基本上是空的。 此外,您正在混合嵌套循环中的计数器: for i in range (0, len(chests)): ... # you override the i value here for i in range(0, len ...
-
你不是以正确的方式调用multipolyfit 。 docstring建议它应该用作multipolyfit.multipolyfit(xs,y,deg) ,其中xs : array_like, shape (M, k)是你的hour , day temps 。 这表明它们需要作为单个数组传递,如下所示: multipolyfit.multipolyfit(np.vstack((hour,day,temps)).T ,load,3) You aren't calling multipolyfit in t ...
-
很高兴看到一些聪明的蔬菜编程。 首先,你的问题。 就像@Vasiliy所说,你有3个指数。 n ,因为你可以用你的条件来保护它。 1很好,因为enumerate总是生成2件事。 那只是留下了m 。 这是你的问题。 假设你在strlist有N元素。 对于strlist每个元素e ,您可以对其应用split() 。 e.split()的元素数量并不总是等于N m守时条件是针对N而不是len(e.split()) ,因此指数超出范围。 要解决此问题,请首先拆分字符串,然后循环遍历它。 当你在它的时候,不妨完全摆脱 ...