2016-03-28 4 views
-5

entschlüsseln Ich bin nicht in der Lage, JSON-Daten zu decodieren, Bitte helfen Sie mir aus diesem heraus. ich tue json kodieren aus folgenden Funktion in .net: -Wie kann ich Daten von JSON.stringify

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>'); 
     } 
    }); 
} 

Jetzt unten Funktion für decode

Hier vermag ich nicht dieses $_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": "[email protected]","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: [email protected]<br> 
Personal E-mail: [email protected]<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); 
} 
+0

Sie Ihre Anfrage an' url senden? – roullie

+2

Frage richtig formatieren –

+1

können Sie bitte den Text Ihrer Frage auf das reduzieren, was tatsächlich benötigt wird? Sie müssen nicht Ihre gesamten JSON-Daten hier posten! –

Antwort

1

Ihr Problem zu entschlüsseln ist ungültig JSON-Text.

Ich habe einen Versuch gemacht, den JSON zu beheben. Sei dir bewusst, es ist hässlich. Sehr hässlich!

So, mit diesen als Eingang:

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

Was ich tat, war versuchen, die JSON-basierte Rekonstruktion auf einigen (wenigen) vorhandenen/korrekten Elemente:

$a = str_replace(["\n","\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)); 

Sie können es sehen hier : ‚url'`:

https://3v4l.org/QdaiV

+0

Danke Alex funktioniert gut –

+0

Gut gemacht Alex, aber kann nicht helfen, aber denke, dass die Frage hätte überarbeitet werden müssen, bevor sie eine Antwort verdient und schlechte Entwickler, die dieses Durcheinander erbt –

+0

@Simpsojo, tatsächlich. Aber von all den minderwertigen Fragen, die ich in letzter Zeit gesehen habe, hat man zumindest etwas Mühe darauf verwendet. Ja, es ist immer noch eine "schlechte" Frage (vielleicht zu lokal). Aber: OP hat schön nachgefragt, das Problem (den JSON) identifiziert und relevanten Code/Info gepostet. Ja, das Problem ist viel tiefer: Jons sollten nicht wie/dafür verwendet werden (Transport von HTML). –

Verwandte Themen