Dim page As XElement = _
<response>
<results>
<result>
<status>OK</status>
<number>phonenumberhere</number>
<wless>y</wless>
<carrier_name>ATT Mobility</carrier_name>
<sms_address>phonenumberhere@txt.att.net</sms_address>
<mms_address>phonenumberhere@mms.att.net</mms_address>
</result>
</results>
</response>
Me.addr = page.Element("sms_address").Value
它在Me.addr = page.Element("sms_address").Value
时崩溃
我需要将sms_address存储为字符串。
有人可以帮忙吗?
答案 0 :(得分:1)
尝试
Dim page As XElement = <response><results><result><status>OK</status><number>phonenumberhere</number><wless>y</wless><carrier_name>ATT Mobility</carrier_name><sms_address>phonenumberhere@txt.att.net</sms_address><mms_address>phonenumberhere@mms.att.net</mms_address></result></results></response>
Me.addr = page.Element("results") _
.Element("result") _
.Element("sms_address").Value
您要查找的元素不在顶部,因此page.Element(&#34; sms_address&#34;)无法找到它。
或者,既然你有幸使用VB.NET,你可以使用
page...<sms_address>.Value
或
page.<results>.<result>.<sms_address>.Value