首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

新浪微博登陆时的JSON数据读取,解决办法

2013-07-09 
新浪微博登陆时的JSON数据读取,急!帮忙看看做新浪账号登陆时通过https://api.weibo.com/2/users/show.json

新浪微博登陆时的JSON数据读取,急!
帮忙看看

做新浪账号登陆时通过https://api.weibo.com/2/users/show.json获得用户数据

格式是JSON如下,保存在temp中,怎么用asp读取screen_name的值呢?
{
"id": 1904178193,
"idstr": "1904178193",
"screen_name": "微博开放平台",
"name": "微博开放平台",
"province": "11",
"city": "8",
"location": "北京 海淀区",
"description": "#平台沙龙两周年#每期沙龙都离不开热爱平台的朋友们,您是否记得2010年10月初次相聚,我们一起见证平台启程;两年间,平台与开发者一同发...",
"url": "",
"profile_image_url": "http://tp2.sinaimg.cn/1904178193/50/5610154048/0",
"profile_url": "openapi",
"domain": "openapi",
"weihao": "",
"gender": "f",
"followers_count": 63987,
"friends_count": 48,
"statuses_count": 1051,
"favourites_count": 2,
"created_at": "Mon Dec 27 17:56:46 +0800 2010",
"following": false,
"allow_all_act_msg": false,
"geo_enabled": true,
"verified": true,
"verified_type": 2,
"remark": "",
"status": {
"created_at": "Tue Feb 26 14:23:23 +0800 2013",
"id": 3549959669956621,
"mid": "3549959669956621",
"idstr": "3549959669956621",
"text": "#轻松一刻#今天是2013年2月26日 星期二,宜1、写单元测试(写单元测试将减少出错)2、重构(代码质量得到提高)http://t.cn/zYGFIFz",
"source": "<a href="http://app.weibo.com/t/feed/1sxHP2" rel="nofollow">专业版微博</a>",
"favorited": false,
"truncated": false,
"in_reply_to_status_id": "",
"in_reply_to_user_id": "",
"in_reply_to_screen_name": "",
"pic_ids": [
"717f7411jw1e26scd15ykj"
],
"thumbnail_pic": "http://ww1.sinaimg.cn/thumbnail/717f7411jw1e26scd15ykj.jpg",
"bmiddle_pic": "http://ww1.sinaimg.cn/bmiddle/717f7411jw1e26scd15ykj.jpg",
"original_pic": "http://ww1.sinaimg.cn/large/717f7411jw1e26scd15ykj.jpg",
"geo": null,
"reposts_count": 0,
"comments_count": 0,
"attitudes_count": 0,
"mlevel": 0,
"visible": {
"type": 0,
"list_id": 0
}
},
"allow_all_comment": false,
"avatar_large": "http://tp2.sinaimg.cn/1904178193/180/5610154048/0",
"verified_reason": "新浪微博开放平台",
"follow_me": false,
"online_status": 0,
"bi_followers_count": 40,
"lang": "zh-cn",
"star": 0,
"mbtype": 0,
"mbrank": 0,
"block_word": 0
}
新浪微博 json
[解决办法]
asp解析JSON还真不好弄,直接字符串截取就行了吧。。

function kv(s,key)
  key=""""&key&""":"""
  dim iStart,iEnd
  iStart=instr(s,key)
  if iStart=0 then exit function
  iStart=iStart+len(key)
  iEnd=instr(iStart,s,"""")
  kv=mid(s,iStart,iEnd-iStart)
end function

response.write kv(temp,"screen_name")

[解决办法]
这个就只能自己写一个函数了
参考如下(来自网络):
Dim sc4Json
Sub InitScriptControl


Set sc4Json = Server.CreateObject("MSScriptControl.ScriptControl")
    sc4Json.Language = "JavaScript"
    sc4Json.AddCode "var itemTemp=null;function getJSArray(arr, index){itemTemp=arr[index];}"
End Sub

Function getJSONObject(strJSON)
    sc4Json.AddCode "var jsonObject = " & strJSON
    Set getJSONObject = sc4Json.CodeObject.jsonObject
End Function

Sub getJSArrayItem(objDest,objJSArray,index)
    On Error Resume Next
    sc4Json.Run "getJSArray",objJSArray, index
    Set objDest = sc4Json.CodeObject.itemTemp
    If Err.number=0 Then Exit Sub
    objDest = sc4Json.CodeObject.itemTemp
End Sub

Dim strTest
strTest = "{name:""alonely"", age:24, email:[""ycplxl1314@163.com"",""ycplxl1314@gmail.com""], family:{parents:[""父亲"",""母亲""],toString:function(){return ""家庭成员"";}}}"
Dim objTest
Call InitScriptControl
Set objTest = getJSONObject(strTest)


[解决办法]
本帖最后由 chinmo 于 2013-04-08 11:06:42 编辑 上面一个是使用了MSScriptControl.ScriptControl,当然还有一种,那就是利用服务端JS的函数来实现
实例代码如下:
<script language="jscript" runat="server">  
Array.prototype.get = function(x) { return this[x]; };  
function parseJSON(strJSON) { return eval("(" + strJSON + ")"); }  
</script>  
<%  
Dim json, obj  
json = "{a:""aaa"", b:{ name:""bb"", value:""text"" }, c:[""item0"", ""item1"", ""item2""]}" 
Set obj = parseJSON(json)  
 
Response.Write obj.a & "<br />" 
Response.Write obj.b.name & "<br />" 
Response.Write obj.c.length & "<br />" 
Response.Write obj.c.get(0) & "<br />" 
 
Set obj = Nothing 
%>

[解决办法]
lz可以看下http://code.google.com/p/aspjson/

热点排行
Bad Request.