Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中PHP数组的反序列化#_C#_Php_Arrays_Serialization - Fatal编程技术网

C# C语言中PHP数组的反序列化#

C# C语言中PHP数组的反序列化#,c#,php,arrays,serialization,C#,Php,Arrays,Serialization,我的任务是只使用C#反序列化序列化php数组。我到处找,但没有找到具体的方法或解决办法。这个解决方案建议使用一个尖锐的序列化库,但它不符合我的目的 下面是我想要反序列化的示例输入数据 a:4:{s:83:"|wsInternalSchedule|acct_ar_/AccountsReceivableAgingDetail-Total/AccountsReceivable";s:69:"Accounts Receivable Aging Detail - Total|acct_ar_|Accou

我的任务是只使用C#反序列化序列化php数组。我到处找,但没有找到具体的方法或解决办法。这个解决方案建议使用一个尖锐的序列化库,但它不符合我的目的

下面是我想要反序列化的示例输入数据

a:4:{s:83:"|wsInternalSchedule|acct_ar_/AccountsReceivableAgingDetail-Total/AccountsReceivable";s:69:"Accounts
 Receivable Aging Detail - Total|acct_ar_|Accounts
 Receivable";s:69:"Accounts Receivable Aging Detail -
 Total|acct_ar_|Accounts
 Receivable";a:5:{s:8:"LayoutID";s:0:"";s:7:"IsChart";s:5:"false";s:11:"Description";s:0:"";s:10:"Preference";s:13:"<Preference/>";s:22:"LayoutParamPreferences";s:729:"<LayoutParamPreferences><LayoutParamPreferences_Item><fieldName>type</fieldName><fieldValue>total</fieldValue></LayoutParamPreferences_Item><LayoutParamPreferences_Item><fieldName>company</fieldName><fieldValue>1</fieldValue></LayoutParamPreferences_Item><LayoutParamPreferences_Item><fieldName>account</fieldName><fieldValue>0220</fieldValue></LayoutParamPreferences_Item><LayoutParamPreferences_Item><fieldName>port</fieldName><fieldValue></fieldValue></LayoutParamPreferences_Item><LayoutParamPreferences_Item><fieldName>sel</fieldName><fieldValue></fieldValue></LayoutParamPreferences_Item><LayoutParamPreferences_Item><fieldName>dsn</fieldName><fieldValue></fieldValue></LayoutParamPreferences_Item></LayoutParamPreferences>";}s:72:"Accounts
 Receivable Aging Detail -
 Total|acct_ar_|wsInternalActiveLayout";s:8:"Original";s:64:"Accounts
 Receivable Aging Detail -
 Total|acct_ar_|wsInternalView";s:802:"<View><LayoutBaseDirectory>/we/templates/</LayoutBaseDirectory><LayoutLanguage>en_US</LayoutLanguage><ApplicationDirectory>acct/ar/</ApplicationDirectory><GridLayoutName>acct.ar.detailViewFormat.xml</GridLayoutName><PrintLayoutName/><CommandToExecute>acct.ARdetail</CommandToExecute><AutoPage>True</AutoPage><ExpandToBand>0</ExpandToBand><Param><ParamName>type</ParamName><ParamValue>total</ParamValue></Param><Param><ParamName>company</ParamName><ParamValue>1</ParamValue></Param><Param><ParamName>account</ParamName><ParamValue>0220</ParamValue></Param><Param><ParamName>port</ParamName><ParamValue/></Param><Param><ParamName>sel</ParamName><ParamValue/></Param><Param><ParamName>dsn</ParamName><ParamValue/></Param><User>tom</User><Group>BMW</Group><Account></Account><ApplCode>ALL</ApplCode></View>";}
a:4:{s:83:| wsInternalSchedule | acpt|u ar|/Accounts接收详细信息总计/Accounts接收;s:69:“账户”
应收账款账龄明细-总应收账款
应收账款编号:69:“应收账款账龄明细表”-
总账目
应收账款;a:5:{s:8:“LayoutID”;s:0:;s:7:“IsChart”;s:5:“false”;s:11:“说明”;s:0:;s:10:“首选项”;s:13:;s:22:“LayoutParamPreferences”;s:729:“TypeTotalCompany1Account10220PortSeldSN”}s:72:“帐户”
应收账款账龄明细-
总计|科目| wsInternalActiveLayout’s:8:“原始”;s:64:“科目”
应收账款账龄明细-
总计| acct|ar|wsInternalView”s:802:“/we/templates/en|u USacct/ar/acct.ar.detailViewFormat.xmlact.ardeTailTrue0TypeTotalCompany1Account0220PortSeldNtomWall”]
我的方法:我创建了一个数据结构,它将保存键、值和数据类型。但是,我无法提取实际的键和值。我想通过在“;”上拆分整个文本来提取它们和“:”。但是,这在嵌套过程中会被卡住

有人能提出一个具体的方法吗?还是我的方法错了

编辑:

下面是我为拆分条目编写的代码。phpMsg是从文件中读取的整个输入文本

       char entry_splitter = ';';           
       char section_splitter = ':';

       // Split into entries    
       string[] entries;
       try
       {
           entries = phpMsg.Trim().Split(entry_splitter);
       }
       catch (NullReferenceException nre)
       {
           entries= null;
       }

           // Split each entry into its sub sections
           if (entries != null)
           {

               string[] sections = new string[50];
               string nestings = null;
               for (int i = 0; i < (entries.Length) - 1; i++)
               {

                   if (entries[i].Contains("{"))
                   {
                       nestings = entries[i].Substring(5);

                       sections = nestings.Split(section_splitter);
                   }
                   else
                   {


                       sections = entries[i].Split(section_splitter);
                   }
char entry_splitter=';';
字符节_拆分器=':';
//分成几个条目
字符串[]项;
尝试
{
条目=phpMsg.Trim().Split(条目拆分器);
}
捕获(NullReferenceException nre)
{
条目=空;
}
//将每个条目拆分为其子部分
if(条目!=null)
{

字符串[]节=新字符串[50]; 字符串嵌套=null; 对于(int i=0;i<(entries.Length)-1;i++) { if(条目[i]。包含(“{”)) { 嵌套=条目[i]。子字符串(5); 截面=嵌套。拆分(截面拆分器); } 其他的 { 节=条目[i]。拆分(节拆分器); }
您能不能先在PHP中使用
取消序列化()
,然后再使用
json\u encode()呢
我认为c#可以读懂它?这是对第一个问题的一次极好的尝试!虽然我一般不知道,但底部看起来像XML,在c#中有现有的解析器。你能不能更清楚一点,到底是什么问题?显示你用来解析的代码?@Abracadver是的,这是更简单和合乎逻辑的方法。然而,它需要在C#中完成,纯粹是因为我的组织最熟悉的原因。@BradleyDotNET是的,底部有XML。但是,它不是必需的。他们只想反序列化PHP数据。我使用以下代码进行拆分。string[]sections=new string[50];字符串嵌套=null;for(int i=0;i<(entries.Length)-1;i++{if(entries[i]。包含(“{”){nestings=entries[i]。子字符串(5);sections=nestings.Split(section\u splitter);}否则{sections=entries[i].Split(section\u splitter);}您不能
unserialize()吗
在PHP中,然后
json\u encode()
我认为c#可以读懂它?这是对第一个问题的一次极好的尝试!虽然我一般不知道,但底部看起来像XML,在c#中有现有的解析器。你能不能更清楚一点,到底是什么问题?显示你用来解析的代码?@Abracadver是的,这是更简单和合乎逻辑的方法。然而,它需要在C#中完成,纯粹是因为我的组织最熟悉的原因。@BradleyDotNET是的,底部有XML。但是,它不是必需的。他们只想反序列化PHP数据。我使用以下代码进行拆分。string[]sections=new string[50];字符串嵌套=null;for(int i=0;i<(entries.Length)-1;i++{if(entries[i]。包含(“{”){nestings=entries[i]。子字符串(5);sections=nestings.Split(section_splitter);}else{sections=entries[i].Split(section_splitter);}