简体   繁体   English

从json编码的字符串中检索值

[英]Retrieve values from json encoded string

I am storing a concatenated string like this: 我存储这样的连接字符串:

echo json_encode($PostedDate.$Places.$Company.$Designation.$ProjectDetails.$DesiredCandidate.$HRName.$HRContact.$Email);

I can split this string using JavaScript and store values in an array. 我可以使用JavaScript拆分此字符串并将值存储在数组中。 But what I want to know is that suppose any of the values above is null, will it affect the array position? 但是我想知道的是,假设上面的任何值都为null,会影响数组的位置吗?

Because, I want to keep the array location fixed. 因为,我想保持阵列位置固定。 For example: 例如:

myArray[0] must hold $PostedDate. myArray [0]必须包含$ PostedDate。

If $PostedDate is null, then also, myArray[0] must be equal to NULL. 如果$ PostedDate为null,则myArray [0]也必须等于NULL。 $Places must not take the position of myArray[0]. $ Places不能位于myArray [0]的位置。

Put it into an array in php and then json_encode the array. 将其放入php中的数组,然后对数组进行json_encode。 Then you dont need to do your crazy split on the javascript side and you dont need to worry about preserving a position in a string. 然后,您无需在javascript端进行疯狂拆分,也无需担心在字符串中保留位置。

put the strings onto a php array like so: 将字符串放入php数组中,如下所示:

echo json_encode(array($PostedDate,$Places,$Company)); 回声json_encode(array($ PostedDate,$ Places,$ Company));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM