2016-07-12 16 views
0

私はvk.com( 'wall.get')にapiリクエストを行い、JSONでresponsを返します。Perl Vk.com API JSONレスポンス

私が使用するモジュール:

use VK::App; 
use JSON qw(decode_json); 
use Data::Dumper; 
use JSON::XS; 

フル応答:

{"response":[1696,{"id":9298,"from_id":-95784908,"to_id":-95784908,"date":1468314922,"marked_as_ads":0,"post_type":"post","text":"Пока рэпера придумывaют нoвые истории,<br>О чем же им написaть я выпью алкоголя.","signer_id":305317129,"can_edit":1,"created_by":305317129,"can_delete":1,"can_pin":1,"media":{"type":"audio","owner_id":2000355235,"item_id":456239648},"attachment":{"type":"photo","photo":{"pid":426327566,"aid":-7,"owner_id":-95784908,"user_id":100,"src":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ece\/lnz0Bz1WuLs.jpg","src_big":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ecf\/yRnLIcZbUNI.jpg","src_small":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ecd\/EESnBXYilMI.jpg","src_xbig":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ed0\/RNR8FS9CNjg.jpg","src_xxbig":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ed1\/pXN8-5o7szc.jpg","width":960,"height":959,"text":"","created":1468281534,"access_key":"fef98dd6d847faf868"}},"attachments":[{"type":"photo","photo":{"pid":426327566,"aid":-7,"owner_id":-95784908,"user_id":100,"src":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ece\/lnz0Bz1WuLs.jpg","src_big":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ecf\/yRnLIcZbUNI.jpg","src_small":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ecd\/EESnBXYilMI.jpg","src_xbig":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ed0\/RNR8FS9CNjg.jpg","src_xxbig":"https:\/\/pp.vk.me\/c633131\/v633131850\/39ed1\/pXN8-5o7szc.jpg","width":960,"height":959,"text":"","created":1468281534,"access_key":"fef98dd6d847faf868"}},{"type":"audio","audio":{"aid":456239648,"owner_id":2000355235,"artist":"Костик ИзХабарэ","title":"ЗаМКАДыш","duration":211,"url":"https:\/\/cs1-43v4.vk-cdn.net\/p14\/5c654491198674.mp3?extra=alCnXJlE-kVhqAR-FhYkeLc3VfVrav607YQqc6RhT--YU-qDG_HlcajsiUqvu9t746CXm57LkPkPLrlG98-Ay72LgAiHjAjBiw1ziotmhGH4n6s9zcs4VPGpGUpgDnhmkHWGxYoG4Nwgt2Q","performer":"Костик ИзХабарэ","album":"2","genre":18}}],"post_source":{"type":"vk"},"comments":{"count":0,"can_post":1},"likes":{"count":0,"user_likes":0,"can_like":1,"can_publish":1},"reposts":{"count":0,"user_reposted":0},"online":0,"reply_count":0}]} 

私はどの

は 'text =>' の後とデータ:: Dumperの後にテキストを解析する必要があります。

$VAR1 = { 
      'response' => [ 
          1696, 
          { 
          'comments' => { 
              'can_post' => 1, 
              'count' => 2 
              }, 
          'attachments' => [ 
               { 
               'type' => 'photo', 
               'photo' => { 
                   'aid' => -7, 
                   'lat' => '55.836657', 
                   'created' =>7, 
                   'height' => 719, 
                   'owner_id' => -95784908, 
                   'text' => '', 
                   'long' => '37.38596', 
                   'src_big' => 'https://pp.vk.me/c633917/v633917838/3d4e7/8uk9QZ0X0ew.jpg', 
                   'src' => 'https://pp.vk.me/c633917/v633917838/3d4e6/JwQKaOWs2zM.jpg', 
                   'access_key' => '290371f54b8b5df024', 
                   'src_xbig' => 'https://pp.vk.me/c633917/v633917838/3d4e8/4hqv0_AH6wE.jpg', 
                   'width' => 960, 
                   'pid' => 426222993, 
                   'post_id' => 9262, 
                   'src_xxbig' => 'https://pp.vk.me/c633917/v633917838/3d4e9/u4oI4yaWF50.jpg', 
                   'src_small' => 'https://pp.vk.me/c633917/v633917838/3d4e5/oq8kQ_qt5cM.jpg', 
                   'user_id' => 100 
                  } 
               } 
              ], 
          'post_type' => 'post', 
          'to_id' => -95784908, 
          'created_by' => 57565838, 
          'attachment' => { 
               'type' => 'photo', 
               'photo' => { 
                  'long' => '37.38596', 
                  'text' => '', 
                  'src_big' => 'https://pp.vk.me/c633917/v633917838/3d4e7/8uk9QZ0X0ew.jpg', 
                  'src' => 'https://pp.vk.me/c633917/v633917838/3d4e6/JwQKaOWs2zM.jpg', 
                  'access_key' => '290371f54b8b5df024', 
                  'src_xbig' => 'https://pp.vk.me/c633917/v633917838/3d4e8/4hqv0_AH6wE.jpg', 
                  'lat' => '55.836657', 
                  'aid' => -7, 
                  'created' =>7, 
                  'height' => 719, 
                  'owner_id' => -95784908, 
                  'src_xxbig' => 'https://pp.vk.me/c633917/v633917838/3d4e9/u4oI4yaWF50.jpg', 
                  'src_small' => 'https://pp.vk.me/c633917/v633917838/3d4e5/oq8kQ_qt5cM.jpg', 
                  'user_id' => 100, 
                  'width' => 960, 
                  'pid' => 426222993, 
                  'post_id' => 9262 
                 } 
              }, 
          'likes' => { 
             'count' => 0, 
             'can_publish' => 1, 
             'user_likes' => 0, 
             'can_like' => 1 
             }, 
          'can_delete' => 1, 
          'text' => "\x{41a}\x{43e}\x{43c}\x{443} \x{43d}\x{443}\x{436}\x{43d}\x{43e}? \x{423} \x{43c}\x{435}\x{43d}\x{44f} 15 \x{431}\x{438}\x{43b}\x{435}\x{442}\x{43e}\x{432})", 
          'online' => 1, 
          'id' => 9263, 
          'from_id' => -95784908, 
          'media' => { 
             'item_id' => 426222993, 
             'type' => 'photo', 
             'thumb_src' => 'https://pp.vk.me/c633917/v633917838/3d4e6/JwQKaOWs2zM.jpg', 
             'owner_id' => -95784908 
             }, 
          'date' => 1468232695, 
          'reposts' => { 
              'count' => 0, 
              'user_reposted' => 0 
             }, 
          'marked_as_ads' => 0, 
          'can_edit' => 1, 
          'can_pin' => 1, 
          'post_source' => { 
               'type' => 'vk' 
              }, 
          'signer_id' => 57565838, 
          'reply_count' => 2 
          } 
         ] 
     }; 
my $msg = GetWallPost(); # request 
$msg = Dumper($msg); 
print $msg; 

JSONを使用して解析しようとすると、またはJSON :: XSを使用します。私はこれをしようとした場合、その後

my $msg = GetWallPost(); 
my $decode= JSON->new->decode($msg); or 
my $decode = JSON::XS->new->utf8->decode ($msg); or 
my $decode = decode_json($msg); 
print $decode->{'response'}[0]{'test'}; get an err -> 
Can't use string ("1702") as a HASH ref while "strict refs" in use at ./testhash.pl line 47. 

- >

print $decode->{'response'}{'text'}; get an err -> 
Not a HASH reference at ./testhash.pl line 47. 

私はデータ:: Dumperの後の$ MSGと同じことを行う場合。

>

Can't use string ("$VAR1 = { 
     'response' ="...) as a HASH ref while "strict refs" in use at ./testhash.pl line 42. 
主な質問 - - 私はこのERRを取得するどのように私は、データを解析できる「テキスト」の後に行く、私が$ MSGでクリアテキストを必要としています。 ありがとう

答えて

0

もちろんです。 ->responseは、JSONの[]によって示されるように、obivously配列です。 $decode->{response}[1]{text}が必要です。

+0

THANKS alot !!!!!!! fnswerはトップに)とても単純に)))))))感謝します) –

関連する問題