duanpa5237 2016-03-28 08:00
浏览 259
已采纳

我如何解码JSON.stringify中的数据

I am unable to decode json data, Please help me out from this. I am doing json encode from following function in .net:-

function(response){
    var jsonString = JSON.stringify(response.newhtml); //stringify the JSON created

    //Send the json data to server
    //---------------------------
    $.ajax({
        type: "POST",
        url: 'url',
        //dataType:"json",
        data: {
            LiRecData: jsonString
        },
    }).done(function(msg){
        $('#load_indicator_store').hide(); //Hide loading icon

        if(msg == 'Success'){
            $('#status_save').html('<span class="status_ok">Save.</span>');
        }
        else {
            $('#status_save').html('<span class="status_error">An error occurred. Please try again after sometime.</span>');
        }
    });
}

Now below function for decode

Here i am unable to decode this $_POST['LiRecData']

$_POST['LiRecData'] =
"{"LinkedIn_URL": "https://in.linkedin.com/in/abcsingh","Full_Name": "Abc Singh (Abc - 7K Connections)","Headline": "A Senior Recruitment Professional - Connecting Employers with their prospective assets (Employee)","Company": "Charter Global","Location": "New Delhi Area, India","Industry": "Information Technology and Services","Email": "venky.s@interproeurope.com","Phone_Number": "+91-999034656 (Mobile)","Connection_Count": "500+6,336","Photo_URL": "https://media.licdn.com/mpr/mpr/sh1rinknp_400_400/p/3/0105/0b5/352/1ad670e.jpg","Summary": "A Senior Recruitment Professional with over 12+ years of overall experience, majorly in Talent/Client Acquisition, Recruitment, IT Staffing, Business Development, Account Management mainly in Staffing space.<br>
<br>
"Connecting Employers with their prospective assets (Employee)"<br>
<br>
Helped a Recruitment Startup to achieve his goal and vision.<br>
<br>
Connecting Dots and bridging between Talents and Dream Companies...<br>
<br>
My personal specialties include:<br>
<br>
Permanent/Contract IT Recruitment, Developing new strategies, Research, Client Acquisition, Business Development, Account Management, Client/Industry Mapping, Marketing, Business terms negotiation, Lead development, professional networking and Presentations.<br>
<br>
To find out how we can assist you or your business please contact me: <br>
<br>
<br>
Official No: +1-999-999-9933 x 513<br>
Official Email: abcgh@abclobal.com<br>
Personal E-mail: abc@gmail.com<br>
Cell: +91-999999-6656<br>
<br>
<br>
I am a [LION] - feel free to network with me<br>
<br>
Specialties: Winning New Business - Candidate Selection - Candidate Handling - Account Management - Recruitment Process - 360 Recruitment Cycle<br>
<br>
About Me: <br>
Abc Singh (Abc Singh), A Senior Recruitment Professional as an Expert in Recruitment, Technical Hiring, Business Development, Account Management, Client Acquisition, Client Delivery, with experience of 12+ years, adept at creative and cost-effective sourcing strategies with a goal of hiring outstanding candidates.","Work_Experience": [{"Title": "Business Development Manager - Staffing/Client Acquisition/Consulting","Company": "Abc","Date_From": "February 2016","Date_To": "Present","Locality": "New Delhi Area, India // Atlanta, GA","More": "Moving further, involved into the Business Development, Client Acquisition, Account Management, majorly in Staffing, Talent Acquisition, Consulting space for the client across Global market. <br>
"},{"Title": "HeadHunter / Candidate Manager / Researcher / Recruitment Specialist - DACH/UK/Europe.","Company": "Interpro People","Date_From": "August 2013","Date_To": "November 2015","Locality": "London/UK, Noida/India","More": "Recruiting for SAP positions viz; SAP SD, MM, WM/EWM, FI/CO, PP-PI-PM, QM, APO, ABAP/Basis, Business Intelligence experts (SAP BI, SAP BW), SAP BI-IP / Integrated Planning, SAP BusinessObjects and SAP BPC expert candidates and run the EU Enterprise Applications division.<br>
Involved into the 360 Recruitment, Candidate Management, Researching, Industry/Client Mapping. <br>
Using Social and professional Networking site to work ahead of job portals.<br>
Use/Search Innovating method of recruitment and implement within the organization."},{"Title": "Resource Manager","Company": "BeyondTek IT","Date_From": "October 2012","Date_To": "August 2013","Locality": "Placentia, CA 92870","More": "Recruitment, Resourcing, Talent Acquisition, Hiring, Technical Recruitment for IT, Software, Business Process, Product Development, Fortune 500 organizations. <br>
Involved into overall Recruitment."},{"Title": "Asst. Manager - Recruitment","Company": "Knowledge Momentum","Date_From": "August 2010","Date_To": "August 2012","Locality": "Noida &amp; North Atlanta, GA","More": ""},{"Title": "Asst. Manager - Recruitment","Company": "Izar Associates Inc","Date_From": "June 2008","Date_To": "July 2010","Locality": "","More": "Play a key role in this organization for the recruitment, resourcing and Full Recruitment Life Cycle. Known for its services and timely delivery with optimum quality. Handled the recruitment for Fortune 500 Organizations including some are in the list of Top 50 Fortune Clients."},{"Title": "Team Lead - IT Recruitment","Company": "Ling Technologies","Date_From": "March 2007","Date_To": "April 2008","Locality": "","More": ""},{"Title": "SENIOR IT RECRUITER","Company": "DatamanUSA, LLC","Date_From": "February 2006","Date_To": "February 2007","Locality": "","More": ""},{"Title": "Sr. Officer - Consulting","Company": "Tusthi Executive Access And Consultants","Date_From": "2005","Date_To": "2006","Locality": "","More": ""},{"Title": "SR. Customer Response Executive","Company": "Reliance Infostream Pvt Ltd","Date_From": "November 2003","Date_To": "May 2005","Locality": "","More": ""}],"Education": [{"Institution_Name": "Sikkim Manipal University","Degree": "MBA, HRM","Grade": "","Date_From": "2011","Date_To": "2013"},{"Institution_Name": "Chhatrapati Shahu Ji Maharaj University","Degree": "Bachelor of Arts (B.A.), Economics & English Literature","Grade": "","Date_From": "2000","Date_To": "2003"},{"Institution_Name": "Kendriya Vidyalaya","Degree": "10 & 12th, Economics, Geography, English","Grade": "","Date_From": "1985","Date_To": "1997"}]},"Top_Skills": [{"Endorse_Count": "7","Endorse_Name": "Entrepreneurship"},{"Endorse_Count": "44","Endorse_Name": "Business Development"},{"Endorse_Count": "16","Endorse_Name": "Account Management"},{"Endorse_Count": "8","Endorse_Name": "Client Acquisition"},{"Endorse_Count": "90","Endorse_Name": "Screening"},{"Endorse_Count": "85","Endorse_Name": "IT Recruitment"},{"Endorse_Count": "34","Endorse_Name": "Leadership"},{"Endorse_Count": "99+","Endorse_Name": "Talent Acquisition"},{"Endorse_Count": "61","Endorse_Name": "Management"},{"Endorse_Count": "99+","Endorse_Name": "Technical Recruiting"}]}"

function decodedata(){
    $data = utf8_encode($_POST['LiRecData']);
    $data = str_replace("'","",$data);

    $json = json_decode($data, true);
    print_r($json);
}
  • 写回答

1条回答 默认 最新

  • dqxsuig64994 2016-03-28 14:40
    关注

    Your problem is the invalid JSON text.

    I've made an attempt to fix the json. Be aware, it's ugly. Very ugly!

    So, having this as input:

    $a = '{"LinkedIn /*trimmed data to fit this format*/ Recruiting"}]}';
    // you use $a = $_POST['LiRecData'];
    

    What I did was try to reconstruct the JSON based on some (few) existing/correct elements:

    $a = str_replace(["
    ","\t",'<br>','</br>'],'',$a);       // remove new lines, tabs and br tags
    $a = preg_replace ( '/([^"])\,([^"])/' , "$1___$2" , $a); // replace commas inside qoutes with SOMETHING
    $a = preg_replace ( '/([^"])\:([^"])/' , "$1__|$2" , $a); // replace semicolon inside qoutes with SOMETHING ELSE
    $a = str_replace('"','',$a);                              // remove all qoutes
    $a = str_replace(':','":"',$a);                           // quote all semicolons 
    $a = str_replace(',','","',$a);                           // quote all commas
    $a = preg_replace ( '/([\{])([a-zA-Z0-9])/' , "$1\"$2" , $a); // {A => {"A
    $a = preg_replace ( '/([\:])\"\s([\[])/' , "$1$2" , $a);      // : " [ => : [
    $a = preg_replace ( '/([a-zA-Z0-9])([\}])/' , "$1\"$2" , $a); // adas} => adas"}
    $a = preg_replace ( '/([\.])(\s{0,})([\}])/' , "$1\"$3" , $a);
    $a = preg_replace ( '/([\"])(\s{1,})([a-zA-Z0-9])/' , "$1$3" , $a); // "   Key" => "Key" trim keys
    $a = str_replace(':" }',':"" }',$a);
    $a = str_replace(']","','],"', $a);
    $a = str_replace("___",",",$a);             // revert comment 2
    $a = str_replace("__|",":",$a);             // revert comment 3
    $a = str_replace(']}","Top', '],"Top',$a);  //manual fix for TopSkils
    
    print_r(json_decode($a,true));
    

    You can see it here:

    https://3v4l.org/QdaiV

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘