Pod Search 出现 JSON ParserError 错误

今天执行 pod search 命令的时候出现了 JSON ParserError 的错误,类似于如下:

Report

  • Run pod search PureLayout
  • List the search result
  • can not get the result list, and shows JSON::ParserError - A JSON text must at least contain two octets!

Stack

1
2
3
4
5
6
7
8
CocoaPods : 1.0.0.beta.8
Ruby : ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
RubyGems : 2.5.1
Host : Mac OS X 10.11.4 (15E65)
Xcode : 7.3 (7D175)
Git : git version 2.6.4 (Apple Git-63)
Ruby lib dir : /Users/name/.rvm/rubies/ruby-2.3.0/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ d8648f8172b778faf0b1fab50c1026c4d7dfa36a

Plugins

1
2
3
4
5
6
cocoapods-deintegrate : 1.0.0.beta.1
cocoapods-plugins : 1.0.0.beta.1
cocoapods-search : 1.0.0.beta.2
cocoapods-stats : 1.0.0.beta.4
cocoapods-trunk : 1.0.0.beta.4
cocoapods-try : 1.0.0.beta.4

Podfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'

target 'MapleStory' do

pod 'AFNetworking', '~> 3.1.0'
pod 'SDWebImage', '~> 3.7.5'
pod 'SVProgressHUD', '~> 2.0.2'
pod 'PureLayout', '~> 3.0.1'
pod 'MJRefresh', '~> 3.1.0'
pod 'UICKeyChainStore', '~> 2.1.0'
pod 'ReactiveCocoa', '~> 2.5'
pod 'JSONModel', '~> 1.2.0'
pod 'DZNEmptyDataSet', '~> 1.7.3'
end

target 'MapleStoryTests' do

end

target 'MapleStoryUITests' do

end

Error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
JSON::ParserError - A JSON text must at least contain two octets!
/Users/name/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `initialize'
/Users/name/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `new'
/Users/name/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `parse'
/Users/name/.rvm/gems/ruby-2.3.0/gems/cocoapods-core-1.0.0.beta.8/lib/cocoapods-core/source/manager.rb:251:in `stored_search_index'
/Users/name/.rvm/gems/ruby-2.3.0/gems/cocoapods-core-1.0.0.beta.8/lib/cocoapods-core/source/manager.rb:187:in `updated_search_index'
/Users/name/.rvm/gems/ruby-2.3.0/gems/cocoapods-core-1.0.0.beta.8/lib/cocoapods-core/source/manager.rb:118:in `search_by_name'
/Users/name/.rvm/gems/ruby-2.3.0/gems/cocoapods-search-1.0.0.beta.2/lib/cocoapods-search/command/search.rb:85:in `local_search'
/Users/name/.rvm/gems/ruby-2.3.0/gems/cocoapods-search-1.0.0.beta.2/lib/cocoapods-search/command/search.rb:61:in `run'
/Users/name/.rvm/gems/ruby-2.3.0/gems/claide-1.0.0.beta.3/lib/claide/command.rb:334:in `run'
/Users/name/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.0.0.beta.8/lib/cocoapods/command.rb:50:in `run'
/Users/name/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.0.0.beta.8/bin/pod:44:in `<top (required)>'
/Users/name/.rvm/gems/ruby-2.3.0/bin/pod:23:in `load'
/Users/name/.rvm/gems/ruby-2.3.0/bin/pod:23:in `<main>'
/Users/name/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/name/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

解决方式也十分的简单:

删除检索文件即可

  • 查看 ~/Library/Caches/CocoaPods 目录下是否有 search_index.json 文件,删除即可。
  • 或者执行下面的命令
1
sudo rm ~/Library/Caches/CocoaPods/search_index.json
  • 之后再次执行 pod search xxx 命令即可。

参考

  • pod search not work JSON ParserError · Issue #5172 · CocoaPods/CocoaPods