티스토리 뷰
반응형
웹뷰에서 화면의 값을 가져와야할 일이 생겼습니다.
html 바디의 pre 태그 안에 json 데이터가 들어있습니다.
<html>
<body>
<pre>
{"status":true,"message":"success","data":{"name":"Gons","url":"https://gonslab.tistory.com/"}}
</pre>
</body>
</html>
<pre id="data"> 이런식으로 아이디를 넣어주면
document.getElementById(“data") 이렇게 손쉽게 찾을 수 있는데
타사에서 넘겨받은 데이터라 수정할 수가 없어서 태그명으로 접근했습니다.
webView.evaluateJavaScript("document.getElementsByTagName('pre')[0].innerHTML") { html, error in
guard let html = html as? String else {
print(error as Any)
return
}
print(html)
}
이렇게 태그 경로대로 작성하면 Json 데이터만 가져올 수 있습니다.
{
"status": "true",
"message": "success",
"data": {
"name": "Gons",
"url": "https://gonslab.tistory.com/"
}
}
이제 이 문자열을 모델로 가공해서 사용하시면 됩니다 ㅎㅎ
iOS
Swift
Xcode
반응형
'iOS Swift + UIKit' 카테고리의 다른 글
iOS Swift UISheetPresentationController.Detent (하프 모달 Half screen size custom modal drag bottom sheet present) (3) | 2022.09.01 |
---|---|
iOS Swift Email Masking (이메일 마스킹 * 표시 ID 아이디 가리기) (0) | 2022.06.01 |
iOS Swift 날짜 차이 구하기 (요일, 시간 사이 간격 변환 계산) Calc Date (0) | 2022.03.02 |
iOS Swift 앱 안끄고 언어 변경 ( 앱 내 언어 설정 ) (4) | 2021.04.05 |
iOS Swift 다국어 설정 - Code Localizing (0) | 2021.04.02 |
댓글