Android Question The XML text obtained through URL is scrambled

songyang

Member
Licensed User
I got the weather information of Beijing from the following code, but I got the wrong one,displayed scrambled.And I also want to know,if I got the right info,how to display informtions in my activity.Thanks!
B4X:
Sub Activity_Create(FirstTime As Boolean)
 Dim job1 As HttpJob
 job1.Initialize("Job1", Me)
 job1.Download("http://wthrcdn.etouch.cn/WeatherApi?city=北京")
End Sub
Sub JobDone (Job As HttpJob)
 Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
 If Job.Success = True Then
  Log(Job.GetString)
 Else
  Log("Error: " & Job.ErrorMessage)
  ToastMessageShow("Error: " & Job.ErrorMessage, True)
 End If
 Job.Release
End Sub
I want the follow result:
HTML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<resp>
<!---->
<city>北京</city>
<updatetime>17:52</updatetime>
<wendu>31</wendu>
<fengli>
<shidu>56%</shidu>
<fengxiang>东北风</fengxiang>
<sunrise_1>05:03</sunrise_1>
<sunset_1>19:37</sunset_1>
<sunrise_2/>
<sunset_2/>
<environment>
<yesterday>
<forecast>
<weather>
<weather>
<weather>
<weather>
<weather>
</forecast>
<zhishus>
</resp>
but the cod give me like this:
HTML:
** Service (httputils2service) Start **
JobName = Job1, Success = true
����������������X[oG�+N�J�*ga��N6�Z�R��OQT!{cSap��'v��
;\L�c�5_bx�_���ݧ�ف5Ƹ!iZ    1�gf���w.���LO8�n���}�|�t�Ot��F�α��}p����EϤ�F�����q����yE�}B�7�-ĵI�3�9:%Ẍc3�Xt�9����ǟ�>��W�׏    �k-x��o��7�cS�ȴ������(��$�3�t�=�of�40l�����03���ԗسq���Ɓ��9�O�n�sBtzd{b����hr�̃��'pzlL�x��W���$)g;T�o��cR��<��6�'S6%P��!��~���r�w9S^��� �$.�`6�QшK0A \���X`�<.^���    _t���(�    >�cQ�.�8�D�
��@_��$�dm���q��������a���He��b��?���9\�`��Q���kLjg���jpf]� =����f8Ҍ�.u��V�X�F��\S��{۔kem����/WRF6uя,�
�\=�]nq�F��L�y�E7cL��s�2{�/Ɩ���Jg��i�œ�sC�G1Ã�z�ND.�Dg����\�tպK-m1�p��z��T��t0d1�+�]�?����
z�J����|���d��9?R�?���v��*��%�:��3M|A����b��~?_����3xހ66�}"���N��k=�y��c����&��6A��+�y�WGp���S�cJԳy��)�1�6�C �E-!Gŏ�����    >��̪�RU�j�a�,K������9\�ԃ|ZTg}r�%���
��1�G�&�DIK����"���j�=-��g��(�:\Nj���Kԛ�<����r5B;��^\h�����
d8A6�ʺ��lj?F]S���fwHh��6��^���rm������,mh��2_�����Cփ�^CM�v��2��΁g����Q�:��欲]P��f}t��lM20QW�x�������H*\ę.�TD�
���N�)��/�\�k�S����fZ��hRs,��l7�$%�ѬGD    �J�5p ��j�~Y�*{�z4OB
H���jV[{ǔ�?yF�]��
`�Δ�5�yVKͪ9��J9,�T�V����3A�p ��N ���~o�NR�\Q�D������a|v���E���Z��k$
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You shouldn't have a JobDone sub.

[B4X] OkHttpUtils2 with Wait For

2. I tested it with this code and it works properly:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim job1 As HttpJob
   job1.Initialize("", Me)
   job1.Download("http://wthrcdn.etouch.cn/WeatherApi?city=北京")
   Wait For (job1) JobDone(j As HttpJob)
   If j.Success Then
       Log(j.GetString)
   End If
   j.Release
End Sub

Which version of B4A are you using? OkHttpUtils2?
 
Upvote 0

songyang

Member
Licensed User
1. You shouldn't have a JobDone sub.

[B4X] OkHttpUtils2 with Wait For

2. I tested it with this code and it works properly:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim job1 As HttpJob
   job1.Initialize("", Me)
   job1.Download("http://wthrcdn.etouch.cn/WeatherApi?city=北京")
   Wait For (job1) JobDone(j As HttpJob)
   If j.Success Then
       Log(j.GetString)
   End If
   j.Release
End Sub

Which version of B4A are you using? OkHttpUtils2?
  • Thank you for your attention and reply,i used HttpUtils2,and when I changed to okHttpUtils2 it worked well.
  • But there's another problem,when I dim a string to save j.getstring,the length can't more than 4K
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The length is not mimited to 4000.
The log output is limited.
Save the result to a file and you ll see that it can be more than 4k
 
Last edited:
Upvote 0
Top