문제

{"linkedin":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n
<skills total=\"11\">\n  
<skill>\n    
    <id>1<\/id>\n    
    <skill>\n      
        <name>C#<\/name>\n    
    <\/skill>\n  
<\/skill>\n  
<skill>\n    
    <id>2<\/id>\n    
    <skill>\n      
        <name>C<\/name>\n    
    <\/skill>\n  
<\/skill>\n  
........................
........................


$id =  getTextBetweenTags($user_profile['linkedin'], 'id');
      $fname = getTextBetweenTags($user_profile['linkedin'], 'first-name');
      $lname = getTextBetweenTags($user_profile['linkedin'], 'last-name');
      $pictureurl = getTextBetweenTags($user_profile['linkedin'], 'picture-url');
      $email = getTextBetweenTags($user_profile['linkedin'], 'email-address');
$headline = getTextBetweenTags($user_profile['linkedin'], 'headline'); 
$summary = getTextBetweenTags($user_profile['linkedin'], 'summary');  

    $interests=getTextBetweenTags($user_profile['linkedin'], 'interests'); 

$user_profile_skills = $OBJ_linkedin->profile('~/skills:(id,skill:(name))');  

$stringData = json_encode($user_profile_skills);
$xml = simplexml_load_string($stringData->linkedin);

How to retrive each value from it using php?. This is the JSON encoded form of skill set getting from linkedin. I am new to these kind of things. Please help me.

도움이 되었습니까?

해결책

You've got an XML document inside your JSON object, so we need to do two things.

Decode the JSON:

$obj = json_decode($jsonString);

Use SimpleXML to parse the XML.

$xmlDoc = simplexml_load_string($obj->linkedin);

As long as the XML is correctly formatted you will be able to process it as your needs dictate using SimpleXML. Further information on SimpleXML can be found here: http://php.net/simplexml

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top