如何从一组网址获取单个URL?(How get Single Url From an Array of urls?)
这是我的代码:
urll = NSURL(string: "http://xxxxxxxxxxx.com/api/?slider=uij6sdnb") let session = NSURLSession.sharedSession() let task = session.dataTaskWithURL(urll) {(NSData, response, error) -> Void in do { let records = try NSJSONSerialization.JSONObjectWithData(NSData!, options: NSJSONReadingOptions.MutableContainers) as! NSArray for record in records { // let urlid = Int(record["slide_id"] as! String) let urimage = record["slide_url"] as! String self.urls = [urimage] print(self.urls.count) } } catch { print("Json Error") } } task.resume()
我打印时:
print(urimage)
它给了我4个这样的网址:
当我打印:
print(urimage[1])
它让我觉得:'subscript'不可用:不能使用Int下标String,请参阅文档注释以供讨论
当我把它放在另一个值时:
var urls = [String]() self.urls = [urimage]
我打印:
print(self.urls.count)
它给了我
1
1
1
1
如何在earch上我可以访问其中一个网址!
我想在imageview上展示它们,但我可以!
This is My Code:
urll = NSURL(string: "http://xxxxxxxxxxx.com/api/?slider=uij6sdnb") let session = NSURLSession.sharedSession() let task = session.dataTaskWithURL(urll) {(NSData, response, error) -> Void in do { let records = try NSJSONSerialization.JSONObjectWithData(NSData!, options: NSJSONReadingOptions.MutableContainers) as! NSArray for record in records { // let urlid = Int(record["slide_id"] as! String) let urimage = record["slide_url"] as! String self.urls = [urimage] print(self.urls.count) } } catch { print("Json Error") } } task.resume()
When I Print :
print(urimage)
it gaves me 4 url like this:
When I print:
print(urimage[1])
It gaves me : 'subscript' is unavailable: cannot subscript String with an Int, see the documentation comment for discussion
When i put it in another value :
var urls = [String]() self.urls = [urimage]
and I print:
print(self.urls.count)
it gaves me
1
1
1
1
How on earch I can access one of this urls !?
I want to Show them on imageview but I can !
原文:https://stackoverflow.com/questions/38550534
最满意答案
你不需要日志文件。 这只会减慢你的脚本:
for /f "skip=1 tokens=3 eol=>" %%a in ('query session %username%') do set "sessionToKill=%%a" echo %sessionToKill%
eol=>
将跳过以>
开头的每一行。 您可以将注销逻辑直接放在for循环中而不是set
。you don't need a log file . this will just slow down your script:
for /f "skip=1 tokens=3 eol=>" %%a in ('query session %username%') do set "sessionToKill=%%a" echo %sessionToKill%
eol=>
will skip every line starting with>
. You can put the logoff logic directly in the for loop instead of theset
.
相关问答
更多-
这应该做的伎俩 - for /f "delims=" %%a in (packageList.txt) do ( set count=0 for /f %%b in (pcList) do for /f %%c in (%%b) do if "%%c"=="%%a" set /a count+=1 echo %%a is installed to !count! PCs ) This should do the trick - for /f "delims=" %%a in (pa ...
-
你不需要日志文件。 这只会减慢你的脚本: for /f "skip=1 tokens=3 eol=>" %%a in ('query session %username%') do set "sessionToKill=%%a" echo %sessionToKill% eol=>将跳过以>开头的每一行。 您可以将注销逻辑直接放在for循环中而不是set 。 you don't need a log file . this will just slow down your script: for /f " ...
-
您可以使用echo ,并将输出重定向到文本文件(参见下面的注释): rem Saved in D:\Temp\WriteText.bat @echo off @echo This is a test> test.txt @echo 123>> test.txt @echo 245.67>> test.txt 输出: D:\Temp>WriteText D:\Temp>type test.txt This is a test 123 245.67 D:\Temp> 笔记: @echo off关闭每个命 ...
-
如何循环使用Windows批处理文件在文本文件中的每一行?(How do you loop through each line in a text file using a windows batch file?)[2021-10-06]
以下的帖子大大有帮助,但是在我的问题中没有提到我需要处理整个行。 这是我找到的工作。 for /F "tokens=*" %%A in (myfile.txt) do [process] %%A 带有星号(*)的令牌关键字将拉出整行的所有文本。 如果你不输入星号,它只会拉出第一个字。 我认为它与空格有关。 对于TechNet上的命令 我感谢所有的帖子! The posts below helped greatly, but did not do what I stated in my question w ... -
要从input.txt中删除someString出现在第10列中的所有行: findstr /rvc:"^.........someString" input.txt >output.txt /r强制进行正则表达式解释 /v返回不匹配的行 /c:"..."指定正则表达式搜索字符串 ^在行的开头锚定搜索 .........匹配任何9个字符 To delete all lines from input.txt where someString appears in column 10: findstr /rv ...
-
嗯,这是cmd中的单线程: for /f %i in (textfile.txt) do @echo . > %i.txt for /f循环遍历文本文件,并在路上进行标记。 幸运的是,你的行中没有空格,否则就会在那里调用类似"delims="东西。 这将使包含点的单行跟在每个新文件中的空格之后。 如果你只想要一个空行,你必须使用echo.>%i.txt 。 如果您只想创建每个文件(UNIX geeks可能只使用touch (1)),您可以使用copy NUL %i.txt 。 如果要在批处理文件中使用它( ...
-
作为解释...... setlocal enabledelayedexpansion 允许我们将变量名称括起来! 表示我们要在运行时而不是在加载时扩展变量。 set OutputString= 使用初始空值定义变量OutputString。 for /f "tokens=3 delims=>" %%A in (Pos.txt) do set OutputString=!OutputString!%%A, 当使用>的分隔符时,我们要保留的文本是第3个标记 对于每次迭代(Pos.t ...
-
将文本文件中的特定行读入批处理文件中的变量(Reading a specific line in a text file to a variable in a batch file)[2022-04-10]
如果你想专门第5行: set "xprvar=" for /F "skip=4 delims=" %%i in (xprtest.txt) do if not defined xprvar set "xprvar=%%i" 要么 for /F "skip=4 delims=" %%i in (xprtest.txt) do set "xprvar=%%i"&goto nextline :nextline 如果你想要最后一行,不管行数如何: for /F "delims=" %%i in (xprtest ... -
搜索文本文件并在批处理文件中添加一行(searching for text file(s) and adding a line in them with batch file)[2024-01-02]
SETLOCAL ENABLEDELAYEDEXPANSION dir /s /a /b "%SystemDrive%\config*.ini" >> %userprofile%\temp.txt set outputFile=in.tmp set _strInsert=TCPPortNumber=870 set _strFind=Random=No for /F "usebackqdelims=" %%G IN ("%userprofile%\temp.txt") DO ( pushd %% ... -
这是一个重复的问题。 但是,好吧,没关系,我只是回答你的问题。 我不知道“523”背后的“)”的目的是什么,但由于你只是连接字符串,请尝试以下脚本: @echo off setlocal EnableDelayedExpansion for /f "tokens=*" %%a in (hxh-chp.txt) do ( set "concatenate_string=!concatenate_string!%%a" ) echo !concatenate_string! pause >nul ...